Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions plugins/openidea-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
.DS_Store
*.log
.codebuddy/

# 仅用于本地开发,不进入插件发布包
AGENTS.md
package-lock.json
15 changes: 15 additions & 0 deletions plugins/openidea-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## 1.0.0 - 2026-12-03

### 新增

- 读取 OpenIDEA 最近项目列表(recent.json),按打开时间倒序展示
- 支持项目名、路径、分支的模糊搜索(多关键词同时匹配)
- 支持项目分组标签:读取 recent-groups.json,副标题展示 [组名],组名可参与搜索
- 调用 OpenIDEA 自带 CLI 打开项目,复用已运行实例
- 支持 macOS 与 Windows(含官方 openidea.cmd 包装脚本与 PATH 兜底)

### 修复

- 缺失判定对齐官方口径:远程路径与 WSL 共享目录不再误判为目录缺失
- 分支从 .git/HEAD 实时读取,兼容 worktree 与 detached HEAD
- 缺失目录与远程项目在启动前拦截并提示,不再透出 CLI 英文报错
21 changes: 21 additions & 0 deletions plugins/openidea-plugin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 zl

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
54 changes: 54 additions & 0 deletions plugins/openidea-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# openidea-plugin

> A ZTools plugin

一个 ZTools 插件:快速打开 OpenIDEA 的最近项目。

## 功能

- 读取 `ai.l0ng.openidea` 的最近项目记录,按打开时间倒序展示
- 支持项目名 / 路径 / 分支模糊搜索(空格分隔多关键词)
- 分支实时读取 `.git/HEAD`,切换分支后无需重开项目
- 一键在 OpenIDEA 中打开项目,复用已运行实例
- 支持项目分组标签:读取 `recent-groups.json`,副标题显示 `[组名]`,组名也可搜索
- 目录已不存在的项目标注 `[目录缺失]`,远程项目标注 `[远程]`

## 数据来源

| 平台 | 路径 |
|---|---|
| macOS | `~/Library/Application Support/ai.l0ng.openidea/recent.json` |
| Windows | `%APPDATA%\ai.l0ng.openidea\recent.json` |

字段:`path`、`name`、`openedAtMs`、`branch`、`missing`。其中 `branch` 与 `missing` 是上次展示时的快照,插件会重新计算。

同目录下的 `recent-groups.json`(可选)保存项目分组,插件只读取 `name` 与 `paths` 做标签展示,不改变排序。

## 启动方式

- macOS:`OpenIDEA.app/Contents/Resources/bin/openidea <path>`
- Windows:`openidea.exe --cli <path>`,或解析官方 `%LOCALAPPDATA%\OpenIDEA\bin\openidea.cmd` 包装脚本

## 开发

```bash
npm install
```

无构建步骤,把本目录作为本地插件导入 ZTools 开发模式即可调试。

## 结构

- `preload.js`:入口,导出 `window.exports`(列表模式)
- `service/features.js`:enter / search / select,列表组装与搜索
- `service/init_service.js`:读取 recent.json
- `utils/launcher.js`:定位 OpenIDEA 并调用其 CLI 打开项目
- `utils/project_path.js`:远程/缺失判定与实时分支读取

## 参考

上游实现:https://github.com/l0ng-ai/openidea

## License

MIT
Binary file added plugins/openidea-plugin/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions plugins/openidea-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "openidea-plugin",
"version": "1.0.0",
"description": "打开 OpenIDEA 最近项目,支持模糊搜索与一键启动",
"author": "zl",
"license": "MIT",
"type": "commonjs",
"devDependencies": {
"@ztools-center/ztools-api-types": "^1.0.1"
}
}
18 changes: 18 additions & 0 deletions plugins/openidea-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "node_modules/@ztools-center/ztools-api-types/resource/ztools.schema.json",
"name": "openidea-plugin",
"title": "OpenIDEA 最近项目",
"description": "打开 OpenIDEA 最近项目,支持模糊搜索与一键启动",
"author": "zl",
"version": "1.0.0",
"platform": ["darwin", "win32"],
"preload": "preload.js",
"logo": "logo.png",
"features": [
{
"code": "all",
"explain": "快速打开 OpenIDEA 最近项目",
"cmds": ["OpenIDEA", "OI", "OID", "oo"]
}
]
}
13 changes: 13 additions & 0 deletions plugins/openidea-plugin/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// ZTools Preload Script window.ztools
// 运行在 Node.js 环境,可以使用 Node.js API
const features = require("./service/features")

// 监听插件进入事件
window.ztools.onPluginEnter(({ code, type, payload }) => {
console.info('Plugin entered:', code, type, payload)
});

// ztools 选项列表
window.exports = {
...features.features
}
137 changes: 137 additions & 0 deletions plugins/openidea-plugin/service/features.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
const { initService } = require("./init_service");
const { launchProject } = require("../utils/launcher");

/**
* 搜索项目
* @param searchWord 搜索词(空格分隔多关键词,需全部命中)
* @returns 项目列表
*/
function search(searchWord) {
const keywordList = String(searchWord || "")
.toLowerCase()
.split(/\s+/)
.filter(Boolean);

if (!keywordList.length) {
return initService.projects.map(buildListItem);
}

return initService.projects
.filter((project) => {
// 项目名、路径、分支都参与匹配,方便按目录或分支快速定位
const haystack = (
project.name + " " + project.path + " " + project.branch + " " + project.group
).toLowerCase();
return keywordList.every((keyword) => haystack.includes(keyword));
})
.map(buildListItem);
}

/**
* 组装列表项(宿主列表模式只渲染 title / description / icon)
* @param project 项目数据
* @returns 列表项
*/
function buildListItem(project) {
const descriptionParts = [];
// 分组标签放最前,便于在长列表里按组扫读
if (project.group) {
descriptionParts.push("[" + project.group + "]");
}
if (project.remote) {
descriptionParts.push("[远程]");
} else if (project.missing) {
descriptionParts.push("[目录缺失]");
}
descriptionParts.push(project.path);
if (project.branch) {
descriptionParts.push(project.branch);
}
const openedAtText = formatOpenedAt(project.openedAtMs);
if (openedAtText) {
descriptionParts.push(openedAtText);
}

return {
title: project.name,
description: descriptionParts.join(" · "),
icon: initService.app ? initService.app.icon : "",
// 以下字段供 select 使用,不影响列表渲染
path: project.path,
branch: project.branch,
missing: project.missing,
remote: project.remote
};
}

/**
* 打开时间格式化:今天/昨天只显示时分,今年省略年份
* @param openedAtMs 打开时间戳(毫秒)
* @returns 展示文本;无效时间返回空串
*/
function formatOpenedAt(openedAtMs) {
const date = new Date(openedAtMs);
if (!openedAtMs || Number.isNaN(date.getTime())) {
return "";
}
const now = new Date();
const pad = (value) => String(value).padStart(2, "0");
const timeText = pad(date.getHours()) + ":" + pad(date.getMinutes());

const isSameDay =
date.getFullYear() === now.getFullYear() &&
date.getMonth() === now.getMonth() &&
date.getDate() === now.getDate();
if (isSameDay) {
return "今天 " + timeText;
}

const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
const isYesterday =
date.getFullYear() === yesterday.getFullYear() &&
date.getMonth() === yesterday.getMonth() &&
date.getDate() === yesterday.getDate();
if (isYesterday) {
return "昨天 " + timeText;
}

const monthDay = pad(date.getMonth() + 1) + "-" + pad(date.getDate());
if (date.getFullYear() === now.getFullYear()) {
return monthDay + " " + timeText;
}
return date.getFullYear() + "-" + monthDay;
}

exports.features = {
all: {
mode: "list",
args: {
// 进入插件应用时调用
enter: (action, callbackSetList) => {
if (window.ztools.isDev() && window.ztools.zbrowser) {
window.ztools.zbrowser.devTools("undocked");
}
try {
initService.init();
} catch (error) {
// 初始化失败也要回调,避免插件空白
console.error("init failed:", error && error.message);
}
callbackSetList(search(""));
},
search: (action, searchWord, callbackSetList) => {
callbackSetList(search(searchWord));
},
select: (action, itemData) => {
const projectPath = itemData && typeof itemData.path === "string" ? itemData.path : "";
window.ztools.hideMainWindow();
launchProject(projectPath);
window.ztools.outPlugin();
},
placeholder: "搜索 OpenIDEA 最近项目(名称 / 路径 / 分支)"
}
}
};

exports.search = search;
exports.formatOpenedAt = formatOpenedAt;
Loading
Loading