ghostty-bg 0.2.0 → 0.2.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Masa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,88 +1,94 @@
1
1
  # ghostty-bg (`gbg`)
2
2
 
3
- Per-directory background colors for Ghostty one command per project.
3
+ ディレクトリごとに Ghostty の背景色を切り替える小さな CLI。プロジェクトごとに 1 コマンド。
4
4
 
5
5
  https://github.com/user-attachments/assets/28d9a5a6-a82c-4da5-b39d-c8d9bf58036f
6
6
 
7
- `gbg` is a tiny, zero-dependency Node CLI. It sends the standard
8
- [OSC 11](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html) escape
9
- sequence to recolor the current window instantly, and remembers the color per
10
- directory. With the shell hook installed, `cd` into a directory and its color
11
- is applied automatically — no Ghostty fork or special API required.
7
+ `gbg` は依存ゼロの小さな Node CLI です。標準の
8
+ [OSC 11](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html) エスケープ
9
+ シーケンスを送って現在のウィンドウの背景色を即座に変え、その色を**ディレクトリ
10
+ ごとに記憶**します。シェルフックを入れておけば、`cd` でそのディレクトリの色が
11
+ 自動で適用されます。Ghostty fork や特別な API は不要です。
12
12
 
13
- ## Install
13
+ > [!TIP]
14
+ > セットアップを自分でやらずに済ませたい場合は、この README をそのまま
15
+ > Claude Code や Codex などのコーディングエージェントに渡して
16
+ > 「この README の通りに gbg をインストールして設定して」と頼んでください。
17
+ > インストールから zsh フックの追加まで代わりにやってくれます。
18
+
19
+ ## インストール
14
20
 
15
21
  ```sh
16
22
  npm install -g ghostty-bg
17
23
  ```
18
24
 
19
- Or run it without installing:
25
+ インストールせずに試す場合:
20
26
 
21
27
  ```sh
22
28
  npx ghostty-bg --color dracula
23
29
  ```
24
30
 
25
- ## Usage
31
+ ## 使い方
26
32
 
27
33
  ```sh
28
- gbg # random color, remembered for this directory
29
- gbg --color dracula # a named theme
30
- gbg --color "#1a2b3c" # a hex value (#rgb or #rrggbb)
31
- gbg teal # shorthand for --color
32
- gbg --no-save tomato # current window only, not remembered
33
- gbg --reset # forget this directory's color, reset background
34
- gbg --list # list available color names
35
- gbg shell-init # print the zsh cd hook
36
- gbg --help # show help
37
- gbg --version # show version
34
+ gbg # パレットからランダムに選び、このディレクトリに記憶
35
+ gbg --color dracula # 名前付きテーマ
36
+ gbg --color "#1a2b3c" # HEX (#rgb または #rrggbb)
37
+ gbg teal # --color の短縮形
38
+ gbg --no-save tomato # 現在のウィンドウのみ(記憶しない)
39
+ gbg --reset # このディレクトリの色を忘れて背景をリセット
40
+ gbg --list # 利用可能な色名の一覧
41
+ gbg shell-init # zsh cd フックを出力
42
+ gbg --help # ヘルプ
43
+ gbg --version # バージョン
38
44
  ```
39
45
 
40
- Short flags: `-c` (color), `-n` (no-save), `-r` (reset), `-l` (list),
41
- `-h` (help), `-v` (version).
46
+ 短縮フラグ: `-c` (color), `-n` (no-save), `-r` (reset), `-l` (list),
47
+ `-h` (help), `-v` (version)
42
48
 
43
- ## Colors
49
+ ## 色の指定
44
50
 
45
- `--color` accepts three kinds of values:
51
+ `--color` 3 種類の値を受け付けます。
46
52
 
47
- - **Named themes** — `dracula`, `nord`, `gruvbox`, `tokyonight`,
48
- `catppuccin`, `solarized`, `github-dark`, and ~40 more. Run `gbg --list`.
49
- - **CSS color names** — `red`, `teal`, `midnightblue`, `rebeccapurple`, ...
50
- - **Hex** — `#rgb` or `#rrggbb`, with or without the leading `#`.
53
+ - **名前付きテーマ** — `dracula`, `nord`, `gruvbox`, `tokyonight`,
54
+ `catppuccin`, `solarized`, `github-dark` など約 40 種類。`gbg --list` で確認。
55
+ - **CSS 色名** — `red`, `teal`, `midnightblue`, `rebeccapurple` など。
56
+ - **HEX** — `#rgb` または `#rrggbb`(先頭の `#` は省略可)。
51
57
 
52
- Running `gbg` with no arguments picks a random color from a curated palette of
53
- dark, readable backgrounds.
58
+ 引数なしの `gbg` は、読みやすい暗色のパレットからランダムに 1 色を選びます。
54
59
 
55
- ## Per-directory colors
60
+ ## ディレクトリごとの色
56
61
 
57
- By default `gbg` does two things:
62
+ デフォルトで `gbg` は次の 2 つを行います。
58
63
 
59
- 1. Recolors the **current window** immediately via OSC 11.
60
- 2. Remembers the color for the **current directory**.
64
+ 1. 現在のウィンドウの背景色を OSC 11 で即座に変更する。
65
+ 2. その色を**現在のディレクトリ**に記憶する。
61
66
 
62
- To make `cd` apply the remembered color automatically, add the hook to your
63
- shell:
67
+ `cd` で記憶した色を自動適用するには、シェルにフックを追加します。
64
68
 
65
69
  ```sh
66
- echo 'eval "$(gbg shell-init)"' >> ~/.zshrc
70
+ grep -q 'gbg shell-init' ~/.zshrc || echo 'eval "$(gbg shell-init)"' >> ~/.zshrc
67
71
  ```
68
72
 
69
- After that:
73
+ 追加後の挙動:
70
74
 
71
- - `cd` into a remembered directory its color is applied.
72
- - `cd` anywhere else the background returns to your theme default.
73
- - `gbg --no-save` applies to the current window without remembering it.
74
- - `gbg --reset` forgets the current directory's color.
75
+ - 記憶済みのディレクトリに `cd` するその色が適用される。
76
+ - それ以外の場所に `cd` する背景がテーマの既定色に戻る。
77
+ - `gbg --no-save` は記憶せず、現在のウィンドウにだけ適用する。
78
+ - `gbg --reset` は現在のディレクトリの色を忘れる。
75
79
 
76
- The hook is plain zsh and reads a small `paths` file with `awk`, so it adds no
77
- Node startup cost on `cd`. Colors are matched by exact directory.
80
+ フックは純粋な zsh で、小さな `paths` ファイルを `awk` で読むだけなので、`cd`
81
+ ごとに Node を起動するコストはかかりません。色は**ディレクトリの完全一致**で
82
+ 照合されます。
78
83
 
79
- ## How It Works
84
+ ## 仕組み
80
85
 
81
- `gbg` writes `ESC ] 11 ; <color> BEL` to the terminal to set the background and
82
- `ESC ] 111 BEL` to reset it. Remembered colors live in
83
- `${XDG_CONFIG_HOME:-~/.config}/gbg/paths` as `<dir><TAB><#hex>` lines.
86
+ `gbg` は背景設定に `ESC ] 11 ; <色> BEL`、リセットに `ESC ] 111 BEL`
87
+ ターミナルへ書き込みます。記憶した色は
88
+ `${XDG_CONFIG_HOME:-~/.config}/gbg/paths` `<ディレクトリ><TAB><#hex>`
89
+ 行として保存されます。
84
90
 
85
- ## Requirements
91
+ ## 必要環境
86
92
 
87
93
  - Node.js >= 18
88
- - A terminal that supports OSC 11 (Ghostty, iTerm2, most modern terminals)
94
+ - OSC 11 に対応したターミナル(Ghostty, iTerm2 など大半のモダンターミナル)
package/bin/gbg.js CHANGED
@@ -121,6 +121,9 @@ function main() {
121
121
  : process.cwd();
122
122
 
123
123
  if (values.reset) {
124
+ if (values.color || positionals[0]) {
125
+ console.error("gbg: --reset ignores any color argument");
126
+ }
124
127
  resetBackground();
125
128
  const had = clearPathColor(cwd);
126
129
  console.error(
@@ -152,8 +155,11 @@ function main() {
152
155
  console.error(`gbg: background → ${label}`);
153
156
 
154
157
  if (!values["no-save"]) {
155
- setPathColor(cwd, result.hex);
156
- console.error(`gbg: remembered for ${cwd} (applies when you cd here)`);
158
+ if (setPathColor(cwd, result.hex)) {
159
+ console.error(`gbg: remembered for ${cwd} (applies when you cd here)`);
160
+ } else {
161
+ console.error("gbg: applied but not remembered (path contains a tab or newline)");
162
+ }
157
163
  }
158
164
  }
159
165
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ghostty-bg",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Change your Ghostty (or any OSC 11 terminal) background color with a single command.",
5
5
  "author": "Masa",
6
6
  "homepage": "https://github.com/MASAKASUNO1/ghostty-path-bg#readme",
package/src/paths.js CHANGED
@@ -34,9 +34,13 @@ function write(map) {
34
34
  }
35
35
 
36
36
  export function setPathColor(dir, hex) {
37
+ // TAB and newline are the file's field/record separators; a path containing
38
+ // either would corrupt unrelated entries, so refuse to store it.
39
+ if (dir.includes("\t") || dir.includes("\n")) return false;
37
40
  const map = read();
38
41
  map.set(dir, hex);
39
42
  write(map);
43
+ return true;
40
44
  }
41
45
 
42
46
  export function clearPathColor(dir) {