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 +21 -0
- package/README.md +55 -49
- package/bin/gbg.js +8 -2
- package/package.json +1 -1
- package/src/paths.js +4 -0
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
|
-
|
|
3
|
+
ディレクトリごとに Ghostty の背景色を切り替える小さな CLI。プロジェクトごとに 1 コマンド。
|
|
4
4
|
|
|
5
5
|
https://github.com/user-attachments/assets/28d9a5a6-a82c-4da5-b39d-c8d9bf58036f
|
|
6
6
|
|
|
7
|
-
`gbg`
|
|
8
|
-
[OSC 11](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
25
|
+
インストールせずに試す場合:
|
|
20
26
|
|
|
21
27
|
```sh
|
|
22
28
|
npx ghostty-bg --color dracula
|
|
23
29
|
```
|
|
24
30
|
|
|
25
|
-
##
|
|
31
|
+
## 使い方
|
|
26
32
|
|
|
27
33
|
```sh
|
|
28
|
-
gbg #
|
|
29
|
-
gbg --color dracula #
|
|
30
|
-
gbg --color "#1a2b3c" #
|
|
31
|
-
gbg teal #
|
|
32
|
-
gbg --no-save tomato #
|
|
33
|
-
gbg --reset #
|
|
34
|
-
gbg --list #
|
|
35
|
-
gbg shell-init #
|
|
36
|
-
gbg --help #
|
|
37
|
-
gbg --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
|
-
|
|
41
|
-
`-h` (help), `-v` (version)
|
|
46
|
+
短縮フラグ: `-c` (color), `-n` (no-save), `-r` (reset), `-l` (list),
|
|
47
|
+
`-h` (help), `-v` (version)。
|
|
42
48
|
|
|
43
|
-
##
|
|
49
|
+
## 色の指定
|
|
44
50
|
|
|
45
|
-
`--color`
|
|
51
|
+
`--color` は 3 種類の値を受け付けます。
|
|
46
52
|
|
|
47
|
-
-
|
|
48
|
-
`catppuccin`, `solarized`, `github-dark
|
|
49
|
-
- **CSS
|
|
50
|
-
- **
|
|
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
|
-
|
|
53
|
-
dark, readable backgrounds.
|
|
58
|
+
引数なしの `gbg` は、読みやすい暗色のパレットからランダムに 1 色を選びます。
|
|
54
59
|
|
|
55
|
-
##
|
|
60
|
+
## ディレクトリごとの色
|
|
56
61
|
|
|
57
|
-
|
|
62
|
+
デフォルトで `gbg` は次の 2 つを行います。
|
|
58
63
|
|
|
59
|
-
1.
|
|
60
|
-
2.
|
|
64
|
+
1. 現在のウィンドウの背景色を OSC 11 で即座に変更する。
|
|
65
|
+
2. その色を**現在のディレクトリ**に記憶する。
|
|
61
66
|
|
|
62
|
-
|
|
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
|
-
|
|
73
|
+
追加後の挙動:
|
|
70
74
|
|
|
71
|
-
- `cd`
|
|
72
|
-
- `cd`
|
|
73
|
-
- `gbg --no-save`
|
|
74
|
-
- `gbg --reset`
|
|
75
|
+
- 記憶済みのディレクトリに `cd` する → その色が適用される。
|
|
76
|
+
- それ以外の場所に `cd` する → 背景がテーマの既定色に戻る。
|
|
77
|
+
- `gbg --no-save` は記憶せず、現在のウィンドウにだけ適用する。
|
|
78
|
+
- `gbg --reset` は現在のディレクトリの色を忘れる。
|
|
75
79
|
|
|
76
|
-
|
|
77
|
-
Node
|
|
80
|
+
フックは純粋な zsh で、小さな `paths` ファイルを `awk` で読むだけなので、`cd`
|
|
81
|
+
ごとに Node を起動するコストはかかりません。色は**ディレクトリの完全一致**で
|
|
82
|
+
照合されます。
|
|
78
83
|
|
|
79
|
-
##
|
|
84
|
+
## 仕組み
|
|
80
85
|
|
|
81
|
-
`gbg`
|
|
82
|
-
|
|
83
|
-
`${XDG_CONFIG_HOME:-~/.config}/gbg/paths`
|
|
86
|
+
`gbg` は背景設定に `ESC ] 11 ; <色> BEL`、リセットに `ESC ] 111 BEL` を
|
|
87
|
+
ターミナルへ書き込みます。記憶した色は
|
|
88
|
+
`${XDG_CONFIG_HOME:-~/.config}/gbg/paths` に `<ディレクトリ><TAB><#hex>` の
|
|
89
|
+
行として保存されます。
|
|
84
90
|
|
|
85
|
-
##
|
|
91
|
+
## 必要環境
|
|
86
92
|
|
|
87
93
|
- Node.js >= 18
|
|
88
|
-
-
|
|
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
|
-
|
|
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
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) {
|