pi-path-bar 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,13 +15,14 @@ A Pi extension for compact directory paths, folder aliases, and theme-aware Git
15
15
  - Short, automatic, and full path display modes.
16
16
  - Display aliases for any folder, without changing actual paths or environment variables.
17
17
  - Theme-aware alias colors and Tide-style Git status indicators.
18
+ - A right-aligned local clock with 12-hour and 24-hour formats.
18
19
  - An interactive settings menu with persistent configuration.
19
20
  - Existing usage statistics, model information, and extension status lines.
20
21
  - Unicode folder names and aliases.
21
22
 
22
23
  ## Installation
23
24
 
24
- After the first npm release, install from npm:
25
+ Install from npm:
25
26
 
26
27
  ```sh
27
28
  pi install npm:pi-path-bar
@@ -29,7 +30,7 @@ pi install npm:pi-path-bar
29
30
  pi -e npm:pi-path-bar
30
31
  ```
31
32
 
32
- Before that release, or to use the Git source, install from GitHub:
33
+ Or install the Git source from GitHub:
33
34
 
34
35
  ```sh
35
36
  pi install git:github.com/johnbitcn/pi-path-bar
@@ -63,11 +64,14 @@ Run `/path-bar`. Use the arrow keys to select an item, Enter or Space to change
63
64
  | Folder icon | On | On, Off |
64
65
  | Git status | On | On, Off |
65
66
  | Session name | On | On, Off |
67
+ | Time format | 24h | 24h, 12h (AM/PM) |
66
68
  | Add folder alias | — | Enter a folder path and a name |
67
69
  | Manage folder aliases | — | Edit or delete aliases |
68
70
 
69
71
  **Native footer** restores Pi's built-in footer. Other display settings are retained but do not apply in that mode.
70
72
 
73
+ The clock shows local time at the right edge of the path line: `09:05` in 24h mode or `09:05 AM` in 12h mode. It refreshes within one second of a minute change, including while idle. Space is reserved for the clock before fitting the path. At widths too small for the clock and a path character, the clock is hidden. Native footer mode stops the clock timer.
74
+
71
75
  ### Path modes
72
76
 
73
77
  - **Short:** always abbreviate intermediate folders to their first grapheme, including Unicode names.
@@ -155,6 +159,7 @@ If `PI_CODING_AGENT_DIR` is set, its directory is used instead. The extension ne
155
159
  "icon": true,
156
160
  "branch": true,
157
161
  "session": true,
162
+ "timeFormat": "24h",
158
163
  "aliases": [
159
164
  { "path": "/home/example/Projects", "name": "Projects" }
160
165
  ]
package/README.zh-CN.md CHANGED
@@ -15,13 +15,14 @@ Pi 底栏扩展。支持简短路径、目录别名和随主题调整的 Git 状
15
15
  - 简短、自动和完整路径显示模式。
16
16
  - 为任意文件夹设置显示别名,不改变实际路径或环境变量。
17
17
  - 随主题调整的别名颜色,以及 Tide 风格的 Git 状态标记。
18
+ - 路径行右侧显示本机时间,支持 12 小时制和 24 小时制。
18
19
  - 交互式设置菜单,自动保存配置。
19
20
  - 保留用量统计、模型信息和其他扩展的状态行。
20
21
  - 支持中文等 Unicode 目录名和别名。
21
22
 
22
23
  ## 安装
23
24
 
24
- 首次发布到 npm 后,可以从 npm 安装:
25
+ 从 npm 安装:
25
26
 
26
27
  ```sh
27
28
  pi install npm:pi-path-bar
@@ -29,7 +30,7 @@ pi install npm:pi-path-bar
29
30
  pi -e npm:pi-path-bar
30
31
  ```
31
32
 
32
- 首次发布前,或需要使用 Git 来源时,从 GitHub 安装:
33
+ 也可以从 GitHub 安装 Git 来源:
33
34
 
34
35
  ```sh
35
36
  pi install git:github.com/johnbitcn/pi-path-bar
@@ -63,11 +64,14 @@ pi -e ./src/index.ts
63
64
  | Folder icon(目录图标) | On | On、Off |
64
65
  | Git status(Git 状态) | On | On、Off |
65
66
  | Session name(会话名称) | On | On、Off |
67
+ | Time format(时间格式) | 24h | 24h、12h(带 AM/PM) |
66
68
  | Add folder alias(添加目录别名) | — | 输入文件夹路径和名称 |
67
69
  | Manage folder aliases(管理目录别名) | — | 修改或删除别名 |
68
70
 
69
71
  **Native footer** 恢复 Pi 原生底栏。其他显示设置会保留,但在该模式下不生效。
70
72
 
73
+ 时间显示在路径行最右侧,使用本机时区。24h 模式显示 `09:05`,12h 模式显示 `09:05 AM`。分钟变化后 1 秒内自动刷新,空闲时也会更新。先为时间预留宽度,再压缩路径。宽度不足以容纳时间和一个路径字符时,隐藏时间。Native footer 模式会停止时间定时器。
74
+
71
75
  ### 路径显示模式
72
76
 
73
77
  - **Short:**始终将中间目录缩写为首个字素,支持中文等 Unicode 名称。
@@ -155,6 +159,7 @@ Short 和 Auto 在宽度不足时将中间目录折叠为 `…`。极窄时,
155
159
  "icon": true,
156
160
  "branch": true,
157
161
  "session": true,
162
+ "timeFormat": "24h",
158
163
  "aliases": [
159
164
  { "path": "/home/example/Projects", "name": "Projects" }
160
165
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-path-bar",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "A Pi extension for compact paths, folder aliases, and theme-aware Git status",
6
6
  "license": "MIT",
@@ -49,9 +49,9 @@
49
49
  "@earendil-works/pi-tui": "*"
50
50
  },
51
51
  "devDependencies": {
52
- "@earendil-works/pi-coding-agent": "^1.1.0",
53
- "@earendil-works/pi-tui": "^1.1.0",
54
- "@types/node": "^26.6.4",
52
+ "@earendil-works/pi-coding-agent": "^1.5.0",
53
+ "@earendil-works/pi-tui": "^1.5.0",
54
+ "@types/node": "^26.6.6",
55
55
  "typescript": "^7.0.2"
56
56
  }
57
57
  }
package/src/config.ts CHANGED
@@ -10,9 +10,10 @@ export interface Config {
10
10
  icon: boolean;
11
11
  branch: boolean;
12
12
  session: boolean;
13
+ timeFormat: "24h" | "12h";
13
14
  aliases: FolderAlias[];
14
15
  }
15
- export const defaults = (): Config => ({ mode: "short", icon: true, branch: true, session: true, aliases: [] });
16
+ export const defaults = (): Config => ({ mode: "short", icon: true, branch: true, session: true, timeFormat: "24h", aliases: [] });
16
17
 
17
18
  export function aliasName(value: string): string {
18
19
  const name = value.trim();
@@ -42,6 +43,10 @@ export function validateConfig(value: unknown): Config {
42
43
  if (!["short", "auto", "full", "native"].includes(data.mode as string)) throw new Error("Invalid path display mode.");
43
44
  config.mode = data.mode as PathMode;
44
45
  }
46
+ if (data.timeFormat !== undefined) {
47
+ if (data.timeFormat !== "24h" && data.timeFormat !== "12h") throw new Error("Invalid time format. Use 24h or 12h.");
48
+ config.timeFormat = data.timeFormat;
49
+ }
45
50
  for (const key of ["icon", "branch", "session"] as const) {
46
51
  if (data[key] === undefined) continue;
47
52
  if (typeof data[key] !== "boolean") throw new Error(`${key} must be a boolean.`);
package/src/index.ts CHANGED
@@ -18,17 +18,35 @@ export default function (pi: ExtensionAPI, configFile = join(getAgentDir(), "pi-
18
18
  catch (error) { ctx.ui.notify(`Cannot read ${store.file}: ${error instanceof Error ? error.message : String(error)}. The file will not be overwritten.`, "error"); }
19
19
  };
20
20
  let activeGit: ReturnType<typeof watchGit> | undefined;
21
+ let disposeFooter: (() => void) | undefined;
21
22
  const install = (ctx: ExtensionContext) => {
22
- activeGit?.dispose();
23
- activeGit = undefined;
23
+ disposeFooter?.();
24
+ disposeFooter = undefined;
24
25
  if (ctx.mode !== "tui") return;
25
26
  if (config.mode === "native") { ctx.ui.setFooter(undefined); return; }
26
27
  ctx.ui.setFooter((tui, theme, data) => {
27
28
  const monitor = config.branch ? watchGit(ctx.sessionManager.getCwd(), () => tui.requestRender()) : undefined;
28
29
  activeGit = monitor;
29
30
  const unsubscribe = data.onBranchChange(() => { monitor?.refresh(); tui.requestRender(); });
31
+ const clock = new Intl.DateTimeFormat("en-US", { hour: "2-digit", minute: "2-digit", hourCycle: config.timeFormat === "12h" ? "h12" : "h23" });
32
+ let minute = Math.floor(Date.now() / 60_000);
33
+ const timer = setInterval(() => {
34
+ const next = Math.floor(Date.now() / 60_000);
35
+ if (next !== minute) { minute = next; tui.requestRender(); }
36
+ }, 1000);
37
+ timer.unref();
38
+ let disposed = false;
39
+ const dispose = () => {
40
+ if (disposed) return;
41
+ disposed = true;
42
+ clearInterval(timer);
43
+ unsubscribe();
44
+ monitor?.dispose();
45
+ if (activeGit === monitor) activeGit = undefined;
46
+ };
47
+ disposeFooter = dispose;
30
48
  return {
31
- dispose() { unsubscribe(); monitor?.dispose(); if (activeGit === monitor) activeGit = undefined; },
49
+ dispose,
32
50
  invalidate() {},
33
51
  render(width: number): string[] {
34
52
  const state = monitor?.value ?? { kind: "none" as const };
@@ -37,7 +55,10 @@ export default function (pi: ExtensionAPI, configFile = join(getAgentDir(), "pi-
37
55
  const name = config.session ? ctx.sessionManager.getSessionName() : undefined;
38
56
  const suffix = `${gitSuffix}${name ? ` • ${name}` : ""}`;
39
57
  const display = resolveDisplayPath(ctx.sessionManager.getCwd(), homedir(), config.aliases);
40
- const lines = [directoryLine(display.path, suffix, width, {
58
+ const time = clock.format(new Date());
59
+ const timeWidth = visibleWidth(time);
60
+ const showClock = width >= timeWidth + 3;
61
+ const path = directoryLine(display.path, suffix, showClock ? width - timeWidth - 2 : width, {
41
62
  mode: config.mode === "native" ? "short" : config.mode,
42
63
  icon: config.icon,
43
64
  aliasName: display.aliasName,
@@ -46,7 +67,8 @@ export default function (pi: ExtensionAPI, configFile = join(getAgentDir(), "pi-
46
67
  alias: (text) => theme.fg("mdLink", text),
47
68
  suffix: (text) => theme.fg(gitColor(state), text.slice(0, gitSuffix.length)) + theme.fg("dim", text.slice(gitSuffix.length)),
48
69
  },
49
- })];
70
+ });
71
+ const lines = [showClock ? path + theme.fg("dim", " ".repeat(width - visibleWidth(path) - timeWidth) + time) : path];
50
72
 
51
73
  const totals = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0 };
52
74
  let hitRate: number | undefined;
@@ -102,7 +124,7 @@ export default function (pi: ExtensionAPI, configFile = join(getAgentDir(), "pi-
102
124
  pi.on("session_start", async (_event, ctx) => { load(ctx); install(ctx); });
103
125
  pi.on("tool_result", () => { activeGit?.refresh(); });
104
126
  pi.on("agent_end", () => { activeGit?.refresh(); });
105
- pi.on("session_shutdown", () => { activeGit?.dispose(); activeGit = undefined; });
127
+ pi.on("session_shutdown", () => { disposeFooter?.(); disposeFooter = undefined; });
106
128
  pi.registerCommand("path-bar", {
107
129
  description: "Configure the path bar and manage folder aliases",
108
130
  handler: async (_args, ctx) => {
package/src/settings.ts CHANGED
@@ -25,15 +25,17 @@ export async function openSettings(ctx: ExtensionContext, get: () => Config, sav
25
25
  const items: SettingItem[] = [
26
26
  { id: "mode", label: "Path display", currentValue: modes[config.mode], values: Object.values(modes), description: "Short: always abbreviate. Auto: abbreviate when needed. Full: never abbreviate." },
27
27
  ...([ ["icon", "Folder icon"], ["branch", "Git status"], ["session", "Session name"] ] as const).map(([id, label]) => ({ id, label, currentValue: config[id] ? "On" : "Off", values: switches })),
28
+ { id: "timeFormat", label: "Time format", currentValue: config.timeFormat, values: ["24h", "12h"], description: "Local time at the right of the path line. 12h includes AM/PM. Not shown in Native footer mode." },
28
29
  { id: "add", label: "Add folder alias", currentValue: "Open", values: ["Open"], description: "Name any folder. A blank path uses the current directory. Only the display changes." },
29
30
  { id: "manage", label: "Manage folder aliases", currentValue: `${config.aliases.length} aliases`, values: ["Open"], description: "Edit a path or name, or delete an alias." },
30
31
  ];
31
32
  const list = new SettingsList(items, 10, getSettingsListTheme(), (id, value) => {
32
33
  selected = id;
33
34
  if (id === "add" || id === "manage") { done(id); return; }
34
- const previous = id === "mode" ? modes[get().mode] : get()[id as "icon" | "branch" | "session"] ? "On" : "Off";
35
+ const previous = id === "mode" ? modes[get().mode] : id === "timeFormat" ? get().timeFormat : get()[id as "icon" | "branch" | "session"] ? "On" : "Off";
35
36
  const success = save((next) => {
36
37
  if (id === "mode") next.mode = (Object.keys(modes) as PathMode[]).find((mode) => modes[mode] === value)!;
38
+ else if (id === "timeFormat") next.timeFormat = value as Config["timeFormat"];
37
39
  else next[id as "icon" | "branch" | "session"] = value === "On";
38
40
  });
39
41
  if (!success) list.updateValue(id, previous);