oops-cli 0.5.0 → 0.7.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.
- checksums.yaml +4 -4
- data/CHANGELOG.ja.md +13 -0
- data/CHANGELOG.md +13 -0
- data/README.ja.md +83 -11
- data/README.md +83 -11
- data/lib/oops/cli.rb +271 -203
- data/lib/oops/doctor.rb +4 -1
- data/lib/oops/gist.rb +72 -0
- data/lib/oops/picker.rb +65 -0
- data/lib/oops/secrets.rb +1 -0
- data/lib/oops/shell/oops.bash +2 -0
- data/lib/oops/shell/oops.fish +2 -0
- data/lib/oops/shell/oops.zsh +2 -0
- data/lib/oops/version.rb +1 -1
- data/lib/oops.rb +2 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c24a418f8fcaabcf3565ae05b07c5dfe1a87ec57f3f3b8ac18c506d083b6fe7c
|
|
4
|
+
data.tar.gz: ffb48126a7abf9e885ed05a1e9c8c14259dd5ca3e33d9cfd17fdd07284e36add
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5033b91ba56b64eb0967f7203be4f68d7a6d067ee5a62b89094ae0c9e2be494ea14870a2f71e1780ec9c17b0ea5c9650855f1a20dfa0e72503de7599c4229959
|
|
7
|
+
data.tar.gz: 16a676598e4f17ae7f9610445f8abb91fede0902c89c7aa417151c6c6eb8598664f96674a8bf2a34605cf0cf99ae28d4b60c28e5b8da6e2a35220767c83e2a60
|
data/CHANGELOG.ja.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
[English](CHANGELOG.md) | 日本語
|
|
4
4
|
|
|
5
|
+
## 0.7.0 - 2026-11-13
|
|
6
|
+
|
|
7
|
+
- 追加: `oops pick` で、このタブの直近 10 コマンドを番号付き(マスク済みのコマンド・終了コード・行数・開始時刻)で並べ、打った番号のものをコピーできるようにしました。番号は 1 つ、複数(`1 3`)、範囲(`2-4`)で打てます。`-n N` で N 件並べ、整形のオプション・`--print`・`--json`・`--gist` は `oops N` と同じように使えます。一覧とプロンプトは標準エラーに出ます([#41](https://github.com/ysb3996-blip/oops/issues/41))。
|
|
8
|
+
- 追加: fish で、fisher(`fisher install ysb3996-blip/oops`)から oops のフックを入れられるようにしました。`conf.d/` のプラグインのファイルは、`config.fish` が oops の Ruby を `PATH` に通し終わる最初のプロンプトまで待ってから動き、`oops` が入っていなければメッセージを出して何もしません([#49](https://github.com/ysb3996-blip/oops/issues/49))。
|
|
9
|
+
- 修正: `oops doctor` がシェルのバージョンを出すようになりました(`shell: zsh 5.9`)。バージョンはシェルが export しない `ZSH_VERSION` / `BASH_VERSION` から読んでいたため、いつも抜けていました。初期化のスニペットが export するように直しています([#96](https://github.com/ysb3996-blip/oops/issues/96))。[@wolf4032](https://github.com/wolf4032) さんの報告([#93](https://github.com/ysb3996-blip/oops/pull/93))。開いているタブは `exec $SHELL` か新しいタブで反映されます。
|
|
10
|
+
- 修正: DigitalOcean API トークンを、記録されたコマンドと出力でマスクするようにしました([#15](https://github.com/ysb3996-blip/oops/issues/15))。[@jdotc1](https://github.com/jdotc1) さんによる貢献([#103](https://github.com/ysb3996-blip/oops/pull/103))。
|
|
11
|
+
|
|
12
|
+
## 0.6.0 - 2026-11-10
|
|
13
|
+
|
|
14
|
+
- 追加: `--gist` で、整えた文字列を GitHub CLI(`gh gist create`)経由で secret gist に上げ、その URL をコピーします。秘密情報は必ずマスクし、`--show-secrets`・`--print`・`--json` との併用は使い方の誤りになります([#44](https://github.com/ysb3996-blip/oops/issues/44))。
|
|
15
|
+
- ドキュメント: README にトラブルシューティングの節を足しました。`oops doctor` のよく出る行の意味と、それぞれの対処を書いています([#92](https://github.com/ysb3996-blip/oops/issues/92))。[@wolf4032](https://github.com/wolf4032) さんによる貢献([#93](https://github.com/ysb3996-blip/oops/pull/93))。
|
|
16
|
+
- ドキュメント: README に Codex CLI から oops を使う方法を書きました。`AGENTS.md` に足す数行があれば、名指ししなくても Codex が失敗したコマンドを読みます。
|
|
17
|
+
|
|
5
18
|
## 0.5.0 - 2026-11-07
|
|
6
19
|
|
|
7
20
|
- 追加: `--json` で、選んだコマンドを JSON の配列(コマンド・ディレクトリ・終了コード・開始と終了の時刻・出力)として標準出力へ書き出せるようにしました。クリップボードと同じように整えてマスクします。スクリプトやエージェント向けです([#43](https://github.com/ysb3996-blip/oops/issues/43))。
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
English | [日本語](CHANGELOG.ja.md)
|
|
4
4
|
|
|
5
|
+
## 0.7.0 - 2026-11-13
|
|
6
|
+
|
|
7
|
+
- Added: `oops pick` lists the last 10 commands of the tab with numbers (command masked, exit code, lines, start time) and copies the ones you type: one number, several (`1 3`) or a range (`2-4`). `-n N` lists N, and the formatting options, `--print`, `--json` and `--gist` work as with `oops N`. The list and the prompt go to stderr ([#41](https://github.com/ysb3996-blip/oops/issues/41)).
|
|
8
|
+
- Added: fish users can install oops's hooks with fisher (`fisher install ysb3996-blip/oops`). The plugin file in `conf.d/` waits for the first prompt, when `config.fish` has put oops's Ruby on `PATH`, and does nothing (with a message) when `oops` is not installed ([#49](https://github.com/ysb3996-blip/oops/issues/49)).
|
|
9
|
+
- Fixed: `oops doctor` shows the shell's version again (`shell: zsh 5.9`). The version came from `ZSH_VERSION` / `BASH_VERSION`, which a shell never exports, so it was always missing; the init snippet now exports it ([#96](https://github.com/ysb3996-blip/oops/issues/96)). Reported by [@wolf4032](https://github.com/wolf4032) in [#93](https://github.com/ysb3996-blip/oops/pull/93). Open tabs pick it up after `exec $SHELL` or in a new tab.
|
|
10
|
+
- Fixed: DigitalOcean API tokens are masked in captured commands and output ([#15](https://github.com/ysb3996-blip/oops/issues/15)). Contributed by [@jdotc1](https://github.com/jdotc1) in [#103](https://github.com/ysb3996-blip/oops/pull/103).
|
|
11
|
+
|
|
12
|
+
## 0.6.0 - 2026-11-10
|
|
13
|
+
|
|
14
|
+
- Added: `--gist` uploads the formatted text as a secret gist through the GitHub CLI (`gh gist create`) and copies the gist's URL. Secrets are always masked; `--show-secrets`, `--print` and `--json` are a usage error with it ([#44](https://github.com/ysb3996-blip/oops/issues/44)).
|
|
15
|
+
- Docs: the README has a Troubleshooting section that explains the common `oops doctor` lines and what to do about each ([#92](https://github.com/ysb3996-blip/oops/issues/92)). Contributed by [@wolf4032](https://github.com/wolf4032) in [#93](https://github.com/ysb3996-blip/oops/pull/93).
|
|
16
|
+
- Docs: the README shows how to use oops from Codex CLI, with an `AGENTS.md` snippet so Codex reads the failed command without being told.
|
|
17
|
+
|
|
5
18
|
## 0.5.0 - 2026-11-07
|
|
6
19
|
|
|
7
20
|
- Added: `--json` writes the selected commands to stdout as a JSON array (command, directory, exit code, start and end times, output), cleaned and masked as on the clipboard, for scripts and agents ([#43](https://github.com/ysb3996-blip/oops/issues/43)).
|
data/README.ja.md
CHANGED
|
@@ -61,6 +61,18 @@ source ~/.oops/oops.plugin.zsh
|
|
|
61
61
|
- `PATH` の Ruby が古いと、`oops: ... init zsh failed (oops needs Ruby 3.3 or later); recording disabled` と出て、記録なしで普通に起動します。
|
|
62
62
|
- プラグインマネージャーは `main` ブランチから更新するので、最新のリリースより先の内容になることがあります。
|
|
63
63
|
|
|
64
|
+
### fisher で入れる(fish)
|
|
65
|
+
|
|
66
|
+
fish なら、[fisher](https://github.com/jorgebucaran/fisher) で小さなプラグインのファイルを入れられます。下の「シェルの設定」にある `config.fish` の 1 行の代わりになります。zsh のプラグインと違って oops 本体は入らないので、先に gem か Homebrew で oops を入れてください。
|
|
67
|
+
|
|
68
|
+
```fish
|
|
69
|
+
fisher install ysb3996-blip/oops
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
- ファイルは `~/.config/fish/conf.d/` に入ります。fish はこれを `config.fish` より先に読むので、`config.fish` が oops の Ruby を `PATH` に通し終わる(mise・rbenv・asdf・`brew shellenv`)最初のプロンプトまで待ってから動きます。そこでシェルを記録用に起動し直すため、タブを開いたときに `config.fish` が 2 回動きます。
|
|
73
|
+
- その時点で `oops` が `PATH` に無いと、`oops: the oops command was not found; ...` と出て、記録なしで普通に起動します。
|
|
74
|
+
- `config.fish` の `oops init fish | source` の行もそのまま使え、そちらが優先されます。両方は要りません。
|
|
75
|
+
|
|
64
76
|
### Claude Code で使う場合
|
|
65
77
|
|
|
66
78
|
Claude Code を使っているなら、Claude Code の中で oops プラグインも入れてください。タブで最後に失敗したコマンドを、貼り付けなしで Claude が読めるようになります([Claude Code のプラグイン](#claude-code-のプラグイン)を参照)。
|
|
@@ -106,6 +118,7 @@ oops init fish | source
|
|
|
106
118
|
| `oops 3` / `oops -n 3` | 直前の 3 コマンドを(古い順に)1 つのコードブロックとしてコピーする |
|
|
107
119
|
| `oops err` | 終了コードが 0 以外だった直近のコマンドをコピーする(成功したコマンドは飛ばす) |
|
|
108
120
|
| `oops err -n 2` | 直近の失敗した 2 コマンドを古い順にコピーする(成功したコマンドは飛ばす) |
|
|
121
|
+
| `oops pick` | 直近の 10 コマンドを番号付きで並べ、打った番号のものをコピーする([下記](#oops-pick)) |
|
|
109
122
|
| `oops init zsh` / `oops init bash` / `oops init fish` | シェルのスニペットを出力する(`eval` 用。fish は `\| source`) |
|
|
110
123
|
| `oops doctor` | 記録・フック・クリップボード・設定・ログサイズを診断する |
|
|
111
124
|
| `oops pause` / `oops resume` | 記録を止める/再開する。停止中は何もディスクに書かれない |
|
|
@@ -114,23 +127,24 @@ oops init fish | source
|
|
|
114
127
|
| `oops record -- <shell>` | 内部用: 記録用プログラムの下でシェルを起動する。スニペットが呼び出す |
|
|
115
128
|
| `oops --version`, `oops --help` | バージョンと使い方 |
|
|
116
129
|
|
|
117
|
-
`oops`、`oops N`、`oops err` のオプション:
|
|
130
|
+
`oops`、`oops N`、`oops err`、`oops pick` のオプション:
|
|
118
131
|
|
|
119
132
|
| オプション | 内容 |
|
|
120
133
|
|---|---|
|
|
121
|
-
| `-n N` | 直前の N コマンドをコピーする(`err` と併用すると直近の失敗した N
|
|
134
|
+
| `-n N` | 直前の N コマンドをコピーする(`err` と併用すると直近の失敗した N コマンド、`pick` と併用すると N 件を並べる) |
|
|
122
135
|
| `--github` | GitHub の issue / PR コメント向けの書式にする |
|
|
123
136
|
| `--time` | 各コマンドの開始時刻を `# 2026-10-31 19:30:09 +09:00` の行として付ける |
|
|
124
137
|
| `--output-only` | `$ コマンド` の行を省き、出力だけをコピーする |
|
|
125
138
|
| `-p`, `--print` | クリップボードの代わりに標準出力へ書き出す(`copied:` 行は出さない) |
|
|
126
139
|
| `--json` | コマンドを JSON で標準出力へ書き出す(スクリプトやエージェント向け) |
|
|
140
|
+
| `--gist` | [GitHub CLI](https://cli.github.com) で secret gist に上げ、その URL をコピーする([下記](#--gist)) |
|
|
127
141
|
| `--show-secrets` | 秘密情報をマスクせず、置換テーブルも適用しない |
|
|
128
142
|
|
|
129
143
|
`N` は正の整数で指定します。件数は位置引数の `N` または `-n N` のどちらかで 1 回だけ指定でき、併用や `-n` の繰り返しは使い方の誤りになります。対象のコマンドが指定件数より少なければ、見つかった分をコピーします。`-n` は上記の書式オプションと併用できます。
|
|
130
144
|
|
|
131
145
|
`oops` 自身はコピー対象になりません。直前のコマンドが `oops` だった場合は、その前のコマンドがコピーされます。
|
|
132
146
|
|
|
133
|
-
終了コード: `0` コピーした(または `--print`・`--json`
|
|
147
|
+
終了コード: `0` コピーした(または `--print`・`--json` で出力した、`--gist` で上げた)、`1` コピーしなかった(記録していない、まだコマンドがない、失敗したコマンドがない、何も選ばなかった、一時停止中、クリップボードのコマンドが失敗、`--gist` で `gh` が失敗)、`2` 使い方の誤り。
|
|
134
148
|
|
|
135
149
|
### 標準の出力
|
|
136
150
|
|
|
@@ -206,6 +220,34 @@ $ bundle exec rspec
|
|
|
206
220
|
]
|
|
207
221
|
```
|
|
208
222
|
|
|
223
|
+
### `--gist`
|
|
224
|
+
|
|
225
|
+
長い出力は、チャットや issue に貼りにくいものです。`oops --gist` は、整えた文字列を secret gist に上げ、文字列の代わりに gist の URL をコピーして表示します。
|
|
226
|
+
|
|
227
|
+
```console
|
|
228
|
+
$ oops err --gist
|
|
229
|
+
gist: https://gist.github.com/you/4f1e8c0b2d9a7e6f5c3b1a0d9e8f7c6b (1 lines)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
oops 自身は GitHub とやり取りしません。[GitHub CLI](https://cli.github.com) の `gh gist create` を呼ぶので、`gh` を入れて、一度 `gh auth login` でログインしておく必要があります。gist の中身は `oops.md` という1ファイルで、説明欄には1つ目のコマンドの行が入ります。`N`・`err`・`-n`・`--github`・`--time`・`--output-only` と併用できます。
|
|
233
|
+
|
|
234
|
+
secret gist は一覧にも検索にも出ませんが、URL を知っていれば誰でも開けます。そのため秘密情報は必ずマスクします。`--show-secrets` を `--gist` と併用すると使い方の誤りになり、`--print`・`--json` との併用も同じです。要らなくなった gist は、gist.github.com か `gh gist delete` で消してください。クリップボードのツールが見つからないときも URL は表示し、コピーできなかったことを警告します。
|
|
235
|
+
|
|
236
|
+
### `oops pick`
|
|
237
|
+
|
|
238
|
+
`oops pick` は、このタブの直近 10 コマンドを古い順に番号付きで並べ、どれをコピーするか聞きます:
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
$ oops pick
|
|
242
|
+
1 $ bundle exec rake (exit 1, 84 lines, 19:30)
|
|
243
|
+
2 $ git status (exit 0, 6 lines, 19:31)
|
|
244
|
+
3 $ curl -s localhost:3000/api (exit 0, 1 line, 19:32)
|
|
245
|
+
pick> 1 3
|
|
246
|
+
copied: $ bundle exec rake (85 lines)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
番号を 1 つ、複数(`1 3`)、または範囲(`2-4`)で打つと、実行した順に、`oops 3` と同じ整形とマスクでコピーします。何も打たずに Enter を押すと何もコピーしません。一覧のコマンドもマスク済みです。`-n 20` で 20 件並べます。整形のオプションもそのまま使えます(`oops pick --github`、`oops pick -p | less` など。一覧と `pick>` は標準エラーに出るので、標準出力には本文だけが出ます)。
|
|
250
|
+
|
|
209
251
|
### `oops status`
|
|
210
252
|
|
|
211
253
|
`oops status` は `recording`・`paused`・`off`(このシェルが記録されていない、またはログが削除された)のどれかを出力し、記録中のときだけ終了コード `0` を返します。エラーは出さないので、プロンプトやスクリプトから呼べます(例: [starship のカスタムモジュール](https://starship.rs/config/#custom-commands))。呼ぶたびに Ruby が起動するため 0.1〜0.2 秒ほどかかります。`off` のときの詳しい理由は `oops doctor` で分かります。
|
|
@@ -222,7 +264,7 @@ $ claude
|
|
|
222
264
|
> `oops -p err` を実行して、失敗したテストを直して。
|
|
223
265
|
```
|
|
224
266
|
|
|
225
|
-
Claude Code では `! oops -p err` と打って、自分で出力を会話に入れることもできます。直近 3 つのコマンドなら `-n 3` を付けます。スクリプトやエージェントが終了コードと出力を別々に扱いたいときは [`--json`](#--json)
|
|
267
|
+
Claude Code では `! oops -p err` と打って、自分で出力を会話に入れることもできます。直近 3 つのコマンドなら `-n 3` を付けます。スクリプトやエージェントが終了コードと出力を別々に扱いたいときは [`--json`](#--json) を使えます。ほかのターミナルのエージェントも、シェルコマンドに環境変数を引き継ぐものなら同じように使えます(例: [Codex CLI](#codex-cli))。
|
|
226
268
|
|
|
227
269
|
特に役立つのは、コマンドを実行し直したくないときです。
|
|
228
270
|
|
|
@@ -259,6 +301,18 @@ $ARGUMENTS
|
|
|
259
301
|
|
|
260
302
|
まだ何も失敗していないときや、タブが記録されていないときは、代わりに oops のメッセージが表示されます。
|
|
261
303
|
|
|
304
|
+
### Codex CLI
|
|
305
|
+
|
|
306
|
+
記録中のタブで起動した [Codex CLI](https://github.com/openai/codex) も `oops -p err` を実行できます(例: `codex exec "Run oops -p err and fix the failing test"`)。Codex の `read-only` のサンドボックスでも動きます。名指ししなくても使ってほしいときは、次の内容を `~/.codex/AGENTS.md`(全プロジェクト共通)かプロジェクトの `AGENTS.md` に足します。
|
|
307
|
+
|
|
308
|
+
```markdown
|
|
309
|
+
## Failed commands in my terminal
|
|
310
|
+
|
|
311
|
+
This terminal tab is recorded by [oops](https://github.com/ysb3996-blip/oops). When I ask about a command I ran that failed, run `oops -p err` to read its command line, output and exit code (secrets are masked) instead of asking me to paste it or running it again. `oops -p -n 3` shows the last 3 commands.
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
これがあれば「さっきのコマンド、なんで失敗したの?」だけで足ります。無いと、Codex は「端末は見えない」と答えます。
|
|
315
|
+
|
|
262
316
|
## 設定
|
|
263
317
|
|
|
264
318
|
任意の設定ファイルは `${XDG_CONFIG_HOME:-~/.config}/oops/config.yml` です。
|
|
@@ -315,6 +369,22 @@ retention_days: 7 # この日数より古いコマンドを削除する。fals
|
|
|
315
369
|
- macOS: `pbcopy` は文字エンコーディングを `LANG` / `LC_*` から決めます。日本語などの非 ASCII 文字が文字化けして届くときは、UTF-8 のロケール(例: `LANG=en_US.UTF-8`)が設定されているか確認してください。SSH 越しで起動したシェルでは設定されていないことがあります。
|
|
316
370
|
- ネイティブ Windows にはまだ対応していません。
|
|
317
371
|
|
|
372
|
+
## トラブルシューティング
|
|
373
|
+
|
|
374
|
+
`oops doctor` は確認ごとに `label: value` の行を 1 つ出力します。おかしい行があれば、下から探してください。例のパスは仮のものです。
|
|
375
|
+
|
|
376
|
+
- `recording: no`: このタブは記録されていません(シェルの行も `hooks: missing` になりますが、この場合はそれで正常です)。rc ファイルに `oops init` の行があり、oops の入った Ruby を `PATH` に通す設定より後ろにあるか確認し(「シェルの設定」を参照)、新しいタブを開いてください。powerlevel10k では、instant prompt のブロックより上に置く必要があります。
|
|
377
|
+
- `recording: yes (/Users/you/.local/state/oops/sessions/... - log file missing)`: このタブのログがありません。後の行が `log writable: no (no status file)` なら、タブを開いたときにログを作れませんでした(そのときタブに `oops: warning: session log unavailable (...)` が出ています)。たいていは状態ディレクトリ(既定は `~/.local/state/oops`)が別のユーザーの持ち物になっている(`sudo` で oops を動かした後など)か、書き込めないのが原因です。自分の持ち物に戻して書き込めるようにしてから、新しいタブを開いてください。直すまでは、新しいタブでも同じ表示になります。そうでなければ、タブを開いたままログが削除されました(`rm -rf ~/.local/state/oops` など)。新しいタブを開いてください。
|
|
378
|
+
- `this terminal: not the recorded tty (this: ..., recorded: ...)`: このシェルは、起動元の記録中のタブとは別の端末(tmux のペインや、記録中のタブから開いた端末ウィンドウ)で動いていて、自分では記録されていません。そのため、ここでの `oops` は起動元のタブのログを読みます。こうしたシェルは通常それ自身で記録されるので、そこでも `oops init` の行が実行されているか、`OOPS_DISABLE` が設定されていないかを確認してください。`this: unknown` のときは、`oops doctor` が端末から実行されていない(記録中のタブで AI コーディングエージェントが実行した場合など)ので、どの端末か判定できていません。プロンプトで自分で `oops doctor` を実行してください。
|
|
379
|
+
- `log writable: no (log-error: ...)`: ログへの書き込みに失敗しました。理由は `log-error:` の後に出ます(ディスクの空き不足など)。原因を直して、新しいタブを開いてください。
|
|
380
|
+
- `paused: yes`: `oops pause` で記録が一時停止しています。`oops resume` を実行してください。
|
|
381
|
+
- 最初の行が `recording: yes` なのに `shell: zsh, hooks: missing`: シェルは記録されていますが、フックが読み込まれていないので、コマンドはログに残りません。行を rc ファイルに書かず、プロンプトで入力した可能性があります。記録される側のシェルは rc ファイルを読み直すので、行が rc ファイルに必要です。足したら新しいタブを開いてください。
|
|
382
|
+
- `pbcopy`・`wl-copy`・`xclip`・`xsel` のつもりが `clipboard: osc52` になる: そのツールが `PATH` にありません(または `DISPLAY` / `WAYLAND_DISPLAY` が設定されていません)。インストールするか、設定ファイルで `clipboard:` を指定してください。SSH 越しなら `osc52` で正常です。
|
|
383
|
+
- `config: /Users/you/.config/oops/config.yml (unknown key: clipbord)`: キーの綴りの誤りです。そのキーは無視されます。`(could not parse /Users/you/.config/oops/config.yml: ...)` は YAML が壊れていて、oops が設定なしで動いていることを表します。`(missing)` は設定ファイルがないだけで、問題ありません。
|
|
384
|
+
- `warning: ~/.bashrc sets a DEBUG trap ...` または `warning: ~/.bashrc assigns PROMPT_COMMAND without appending ...`(bash のみ): `oops init bash` の行より下の行が、oops のフックを置き換えることがあります。その行を oops の行より上に移してください。`PROMPT_COMMAND` の代入なら、今の値を残す形にしてもかまいません(`PROMPT_COMMAND="...;$PROMPT_COMMAND"`)。
|
|
385
|
+
|
|
386
|
+
どれにも当てはまらないときは、`oops doctor` の出力全体を付けて[バグ報告](https://github.com/ysb3996-blip/oops/issues/new?template=bug_report.md)を出してください(セッションログは貼らないでください)。
|
|
387
|
+
|
|
318
388
|
## 開発
|
|
319
389
|
|
|
320
390
|
### 手元の環境を整える
|
|
@@ -353,11 +423,11 @@ bundle exec exe/oops doctor
|
|
|
353
423
|
|
|
354
424
|
```sh
|
|
355
425
|
gem build oops-cli.gemspec
|
|
356
|
-
gem install ./oops-cli-0.
|
|
426
|
+
gem install ./oops-cli-0.7.0.gem # ファイル名は lib/oops/version.rb に合わせる
|
|
357
427
|
rbenv rehash # rbenv を使う場合のみ
|
|
358
428
|
```
|
|
359
429
|
|
|
360
|
-
- gem は Ruby のバージョンごとに入ります。新しいタブが、インストールした Ruby とは別の Ruby を使っていると(たとえばリポジトリは 4.0.9 を指定しているのに、標準の Ruby が 3.3.5 の場合)、シェルの起動時に oops が見つからなくなります(bash では `bash: oops: command not found`、zsh では `command not found: oops` と出ます)。その Ruby でも `gem install` を実行してください(例: `RBENV_VERSION=3.3.5 gem install ./oops-cli-0.
|
|
430
|
+
- gem は Ruby のバージョンごとに入ります。新しいタブが、インストールした Ruby とは別の Ruby を使っていると(たとえばリポジトリは 4.0.9 を指定しているのに、標準の Ruby が 3.3.5 の場合)、シェルの起動時に oops が見つからなくなります(bash では `bash: oops: command not found`、zsh では `command not found: oops` と出ます)。その Ruby でも `gem install` を実行してください(例: `RBENV_VERSION=3.3.5 gem install ./oops-cli-0.7.0.gem`)。
|
|
361
431
|
- 変更のたびに入れ直してください。インストールされた gem はコピーで、チェックアウトへのリンクではありません。
|
|
362
432
|
- 削除するには `gem uninstall oops-cli` です。
|
|
363
433
|
- `eval "$(oops init zsh)"` は、プロンプトで打つだけでなく rc ファイルに書いてください。記録されるシェルは rc ファイルを読み直すため、行がないとフックが入りません(`oops doctor` に `hooks: missing` と出ます)。
|
|
@@ -375,7 +445,7 @@ rbenv rehash # rbenv を使う場合のみ
|
|
|
375
445
|
|
|
376
446
|
## コントリビュート
|
|
377
447
|
|
|
378
|
-
バグ報告、アイデア、プルリクエストを歓迎します。[CONTRIBUTING.ja.md](CONTRIBUTING.ja.md) を読んでください。`good first issue` のラベルが付いた issue
|
|
448
|
+
バグ報告、アイデア、プルリクエストを歓迎します。[CONTRIBUTING.ja.md](CONTRIBUTING.ja.md) を読んでください。`good first issue` のラベルが付いた issue が、始めやすい入口です。大きさ順に並べた一覧は [New contributors: start here](https://github.com/ysb3996-blip/oops/issues/100) にあります。プルリクエストには、テストと rubocop の結果、新しいタブでの動作確認を必ず貼ってください([プルリクエストに必ず貼るもの](CONTRIBUTING.ja.md#プルリクエストに必ず貼るもの))。
|
|
379
449
|
|
|
380
450
|
## 貢献してくれた人たち
|
|
381
451
|
|
|
@@ -387,10 +457,12 @@ rbenv rehash # rbenv を使う場合のみ
|
|
|
387
457
|
<table>
|
|
388
458
|
<tbody>
|
|
389
459
|
<tr>
|
|
390
|
-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ysb3996-blip"><img src="https://avatars.githubusercontent.com/u/257992595?v=4
|
|
391
|
-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ricky9408"><img src="https://avatars.githubusercontent.com/u/49530170?v=4
|
|
392
|
-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/agenticsymphony-tech"><img src="https://avatars.githubusercontent.com/u/326739730?v=4
|
|
393
|
-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ShahadatTest"><img src="https://avatars.githubusercontent.com/u/179203101?v=4
|
|
460
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ysb3996-blip"><img src="https://avatars.githubusercontent.com/u/257992595?v=4&size=80" width="80px" height="80px" alt="ysb3996-blip"/><br /><sub><b>ysb3996-blip</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=ysb3996-blip" title="Code">💻</a> <a href="https://github.com/ysb3996-blip/oops/commits?author=ysb3996-blip" title="Documentation">📖</a> <a href="https://github.com/ysb3996-blip/oops/commits?author=ysb3996-blip" title="Tests">⚠️</a> <a href="#maintenance-ysb3996-blip" title="Maintenance">🚧</a></td>
|
|
461
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ricky9408"><img src="https://avatars.githubusercontent.com/u/49530170?v=4&size=80" width="80px" height="80px" alt="Sanghyuk Lee"/><br /><sub><b>Sanghyuk Lee</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=ricky9408" title="Code">💻</a></td>
|
|
462
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/agenticsymphony-tech"><img src="https://avatars.githubusercontent.com/u/326739730?v=4&size=80" width="80px" height="80px" alt="agenticsymphony-tech"/><br /><sub><b>agenticsymphony-tech</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=agenticsymphony-tech" title="Documentation">📖</a></td>
|
|
463
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ShahadatTest"><img src="https://avatars.githubusercontent.com/u/179203101?v=4&size=80" width="80px" height="80px" alt="ShahadatTest"/><br /><sub><b>ShahadatTest</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=ShahadatTest" title="Code">💻</a></td>
|
|
464
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/wolf4032"><img src="https://avatars.githubusercontent.com/u/144633223?v=4&size=80" width="80px" height="80px" alt="wolf4032"/><br /><sub><b>wolf4032</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=wolf4032" title="Documentation">📖</a></td>
|
|
465
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jdotc1"><img src="https://avatars.githubusercontent.com/u/138259519?v=4&size=80" width="80px" height="80px" alt="Jeff"/><br /><sub><b>Jeff</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=jdotc1" title="Code">💻</a></td>
|
|
394
466
|
</tr>
|
|
395
467
|
</tbody>
|
|
396
468
|
</table>
|
data/README.md
CHANGED
|
@@ -61,6 +61,18 @@ source ~/.oops/oops.plugin.zsh
|
|
|
61
61
|
- If the Ruby on `PATH` is too old, the shell prints `oops: ... init zsh failed (oops needs Ruby 3.3 or later); recording disabled` and starts as usual, without recording.
|
|
62
62
|
- Plugin managers update from the `main` branch, which can be ahead of the latest release.
|
|
63
63
|
|
|
64
|
+
### With fisher (fish)
|
|
65
|
+
|
|
66
|
+
For fish, [fisher](https://github.com/jorgebucaran/fisher) can install a small plugin file that replaces the `config.fish` line below. Unlike the zsh plugin it does not bring oops itself: install the gem or the Homebrew formula first.
|
|
67
|
+
|
|
68
|
+
```fish
|
|
69
|
+
fisher install ysb3996-blip/oops
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
- The file goes into `~/.config/fish/conf.d/`, which fish reads before `config.fish`, so it waits for the first prompt, when `config.fish` has put oops's Ruby on `PATH` (mise, rbenv, asdf, `brew shellenv`). Then the shell starts again under the recorder, so `config.fish` runs twice at the start of a tab.
|
|
73
|
+
- If `oops` is not on `PATH` by then, the shell prints `oops: the oops command was not found; ...` and starts as usual, without recording.
|
|
74
|
+
- An `oops init fish | source` line in `config.fish` still works and takes precedence; you do not need both.
|
|
75
|
+
|
|
64
76
|
### For Claude Code
|
|
65
77
|
|
|
66
78
|
If you use Claude Code, also install the oops plugin inside it, so Claude can read the last command that failed in your tab without you pasting it (see [Claude Code plugin](#claude-code-plugin)):
|
|
@@ -106,6 +118,7 @@ To turn oops off for one shell, start it with `OOPS_DISABLE=1` (for example `OOP
|
|
|
106
118
|
| `oops 3` / `oops -n 3` | Copy the last 3 commands (oldest first) as one code block |
|
|
107
119
|
| `oops err` | Copy the last command that exited non-zero, skipping over successful ones |
|
|
108
120
|
| `oops err -n 2` | Copy the last 2 failed commands (oldest first), skipping over successful ones |
|
|
121
|
+
| `oops pick` | List the last 10 commands with numbers and copy the ones you type ([below](#oops-pick)) |
|
|
109
122
|
| `oops init zsh` / `oops init bash` / `oops init fish` | Print the shell snippet (for `eval`, or `\| source` in fish) |
|
|
110
123
|
| `oops doctor` | Diagnose recording, hooks, clipboard, config and log size |
|
|
111
124
|
| `oops pause` / `oops resume` | Stop and restart recording. While paused, nothing is written to disk |
|
|
@@ -114,23 +127,24 @@ To turn oops off for one shell, start it with `OOPS_DISABLE=1` (for example `OOP
|
|
|
114
127
|
| `oops record -- <shell>` | Internal: runs a shell under the recorder. The snippet calls this |
|
|
115
128
|
| `oops --version`, `oops --help` | Version and usage |
|
|
116
129
|
|
|
117
|
-
Options for `oops`, `oops N` and `oops
|
|
130
|
+
Options for `oops`, `oops N`, `oops err` and `oops pick`:
|
|
118
131
|
|
|
119
132
|
| Option | What it does |
|
|
120
133
|
|---|---|
|
|
121
|
-
| `-n N` | Copy the last N commands (with `err`, the last N failed commands) |
|
|
134
|
+
| `-n N` | Copy the last N commands (with `err`, the last N failed commands; with `pick`, list N) |
|
|
122
135
|
| `--github` | Format for a GitHub issue or PR comment |
|
|
123
136
|
| `--time` | Add the time each command started as a `# 2026-10-31 19:30:09 +09:00` line |
|
|
124
137
|
| `--output-only` | Leave out the `$ command` line and copy only the output |
|
|
125
138
|
| `-p`, `--print` | Write the text to stdout instead of the clipboard (no `copied:` line) |
|
|
126
139
|
| `--json` | Write the commands as JSON to stdout, for scripts and agents |
|
|
140
|
+
| `--gist` | Upload the text as a secret gist with the [GitHub CLI](https://cli.github.com) and copy its URL ([below](#--gist)) |
|
|
127
141
|
| `--show-secrets` | Do not mask secrets and do not apply the replace table |
|
|
128
142
|
|
|
129
143
|
`N` must be a positive integer. Specify the command count once, either as a positional `N` or with `-n N`; combining them or repeating `-n` is a usage error. If fewer matching commands are available, oops copies those it finds. `-n` can be combined with the formatting options above.
|
|
130
144
|
|
|
131
145
|
`oops` never copies itself: if the previous command was `oops`, you get the command before it.
|
|
132
146
|
|
|
133
|
-
Exit codes: `0` copied (or printed with `--print` or `--json`), `1` nothing copied (not recording, no command yet, no failed command, paused,
|
|
147
|
+
Exit codes: `0` copied (or printed with `--print` or `--json`, or uploaded with `--gist`), `1` nothing copied (not recording, no command yet, no failed command, nothing picked, paused, the clipboard command failed, or `gh` failed with `--gist`), `2` usage error.
|
|
134
148
|
|
|
135
149
|
### Default output
|
|
136
150
|
|
|
@@ -206,6 +220,34 @@ $ bundle exec rspec
|
|
|
206
220
|
]
|
|
207
221
|
```
|
|
208
222
|
|
|
223
|
+
### `--gist`
|
|
224
|
+
|
|
225
|
+
A long output is awkward to paste into a chat or an issue. `oops --gist` uploads the formatted text as a secret gist and copies the gist's URL instead, then prints it:
|
|
226
|
+
|
|
227
|
+
```console
|
|
228
|
+
$ oops err --gist
|
|
229
|
+
gist: https://gist.github.com/you/4f1e8c0b2d9a7e6f5c3b1a0d9e8f7c6b (1 lines)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
oops does not talk to GitHub itself: it runs `gh gist create` from the [GitHub CLI](https://cli.github.com), so you need `gh` installed and logged in once with `gh auth login`. The gist holds one file, `oops.md`, and its description is the first command line. It works with `N`, `err`, `-n`, `--github`, `--time` and `--output-only`.
|
|
233
|
+
|
|
234
|
+
A secret gist is not listed or searchable, but anyone who has the URL can open it, so secrets are always masked: `--show-secrets` is a usage error with `--gist`, and so are `--print` and `--json`. Delete a gist you no longer need on gist.github.com or with `gh gist delete`. If no clipboard tool is found, the URL is still printed and oops warns that it was not copied.
|
|
235
|
+
|
|
236
|
+
### `oops pick`
|
|
237
|
+
|
|
238
|
+
`oops pick` lists the last 10 commands of this tab, oldest first, and asks which to copy:
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
$ oops pick
|
|
242
|
+
1 $ bundle exec rake (exit 1, 84 lines, 19:30)
|
|
243
|
+
2 $ git status (exit 0, 6 lines, 19:31)
|
|
244
|
+
3 $ curl -s localhost:3000/api (exit 0, 1 line, 19:32)
|
|
245
|
+
pick> 1 3
|
|
246
|
+
copied: $ bundle exec rake (85 lines)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Type one number, several (`1 3`), or a range (`2-4`); they are copied in the order they ran, with the same formatting and masking as `oops 3`. An empty answer copies nothing. The list shows commands already masked. `-n 20` lists 20 instead, and the formatting options work as usual: `oops pick --github`, or `oops pick -p | less` (the list and the prompt go to stderr, so only the text reaches stdout).
|
|
250
|
+
|
|
209
251
|
### `oops status`
|
|
210
252
|
|
|
211
253
|
`oops status` prints `recording`, `paused` or `off` (this shell is not recorded, or its log was deleted) and exits `0` only when recording. It prints no error, so a prompt or script can call it, for example with a [starship custom module](https://starship.rs/config/#custom-commands). Each call starts Ruby, which takes roughly 0.1 to 0.2 seconds; `oops doctor` tells more when the answer is `off`.
|
|
@@ -222,7 +264,7 @@ $ claude
|
|
|
222
264
|
> Run `oops -p err` and fix the failing test.
|
|
223
265
|
```
|
|
224
266
|
|
|
225
|
-
In Claude Code you can also type `! oops -p err` to put the output into the conversation yourself. Add `-n 3` for the last 3 commands, or use [`--json`](#--json) when a script or agent wants the exit code and output as separate fields. Other terminal agents work the same way when they pass your environment to their shell commands.
|
|
267
|
+
In Claude Code you can also type `! oops -p err` to put the output into the conversation yourself. Add `-n 3` for the last 3 commands, or use [`--json`](#--json) when a script or agent wants the exit code and output as separate fields. Other terminal agents work the same way when they pass your environment to their shell commands; see [Codex CLI](#codex-cli) for one.
|
|
226
268
|
|
|
227
269
|
This helps most when running the command again is a bad idea:
|
|
228
270
|
|
|
@@ -259,6 +301,18 @@ $ARGUMENTS
|
|
|
259
301
|
|
|
260
302
|
When nothing has failed yet, or the tab is not recorded, Claude Code shows oops's message instead.
|
|
261
303
|
|
|
304
|
+
### Codex CLI
|
|
305
|
+
|
|
306
|
+
[Codex CLI](https://github.com/openai/codex) started in a recorded tab can run `oops -p err` too, for example `codex exec "Run oops -p err and fix the failing test"`. It works in Codex's `read-only` sandbox as well. To have it look there without being told, add this to `~/.codex/AGENTS.md` (all projects) or to the project's `AGENTS.md`:
|
|
307
|
+
|
|
308
|
+
```markdown
|
|
309
|
+
## Failed commands in my terminal
|
|
310
|
+
|
|
311
|
+
This terminal tab is recorded by [oops](https://github.com/ysb3996-blip/oops). When I ask about a command I ran that failed, run `oops -p err` to read its command line, output and exit code (secrets are masked) instead of asking me to paste it or running it again. `oops -p -n 3` shows the last 3 commands.
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
With that in place, "my last command failed, why?" is enough. Without it, Codex answers that it cannot see your terminal.
|
|
315
|
+
|
|
262
316
|
## Configuration
|
|
263
317
|
|
|
264
318
|
Optional file at `${XDG_CONFIG_HOME:-~/.config}/oops/config.yml`:
|
|
@@ -315,6 +369,22 @@ Masking is pattern based, so it is a safety net, not a guarantee: a secret in a
|
|
|
315
369
|
- macOS: `pbcopy` chooses its text encoding from `LANG` / `LC_*`. If Japanese or other non-ASCII text arrives garbled, check that a UTF-8 locale is set (for example `LANG=en_US.UTF-8`), which can be missing in shells started over SSH.
|
|
316
370
|
- Native Windows is not supported yet.
|
|
317
371
|
|
|
372
|
+
## Troubleshooting
|
|
373
|
+
|
|
374
|
+
`oops doctor` prints one `label: value` line per check. When a line looks wrong, find it below. Paths in the examples are placeholders.
|
|
375
|
+
|
|
376
|
+
- `recording: no`: this tab is not recorded (the shell line then shows `hooks: missing` too, which is expected). Check that the `oops init` line is in your rc file and comes after whatever puts oops's Ruby on your `PATH` (see "Set up your shell"), then open a new tab. With powerlevel10k, the line must be above the instant prompt block.
|
|
377
|
+
- `recording: yes (/Users/you/.local/state/oops/sessions/... - log file missing)`: this tab's log does not exist. If a later line says `log writable: no (no status file)`, the recorder could not create the log when the tab opened (the tab then printed `oops: warning: session log unavailable (...)`), usually because the state directory (`~/.local/state/oops` by default) belongs to another user, for example after running oops with `sudo`, or cannot be written. Make it yours and writable again, then open a new tab; until then every new tab shows the same. Otherwise the log was deleted while the tab was open (for example with `rm -rf ~/.local/state/oops`); open a new tab.
|
|
378
|
+
- `this terminal: not the recorded tty (this: ..., recorded: ...)`: this shell runs on another terminal than the recorded tab it was started from (a tmux pane, or a terminal window opened from a recorded tab) and was not recorded on its own, so `oops` here reads the other tab's log. Such a shell is normally recorded on its own; check that the `oops init` line runs there too and that `OOPS_DISABLE` is not set. With `this: unknown`, `oops doctor` was not run from a terminal (for example an AI coding agent ran it in a recorded tab), so it cannot tell which terminal it is on; run `oops doctor` yourself at the prompt.
|
|
379
|
+
- `log writable: no (log-error: ...)`: writing the log failed; the message after `log-error:` says why (for example a full disk). Fix that and open a new tab.
|
|
380
|
+
- `paused: yes`: recording was paused with `oops pause`. Run `oops resume`.
|
|
381
|
+
- `shell: zsh, hooks: missing` while the first line says `recording: yes`: the shell is recorded but its hooks did not load, so commands are not logged. The line was probably typed at the prompt instead of being in the rc file; the recorded shell reads the rc file again and needs the line there. Open a new tab after adding it.
|
|
382
|
+
- `clipboard: osc52` when you expected `pbcopy`, `wl-copy`, `xclip` or `xsel`: that tool is not on `PATH` (or `DISPLAY` / `WAYLAND_DISPLAY` is not set). Install it, or set `clipboard:` in the config. Over SSH, `osc52` is expected.
|
|
383
|
+
- `config: /Users/you/.config/oops/config.yml (unknown key: clipbord)`: a misspelled key; it is ignored. `(could not parse /Users/you/.config/oops/config.yml: ...)` means the YAML is broken and oops runs without a config. `(missing)` only means there is no config file, which is fine.
|
|
384
|
+
- `warning: ~/.bashrc sets a DEBUG trap ...` or `warning: ~/.bashrc assigns PROMPT_COMMAND without appending ...` (bash only): a line below the `oops init bash` line can replace oops's hooks. Move it above the oops line. A `PROMPT_COMMAND` assignment can instead keep what is there: `PROMPT_COMMAND="...;$PROMPT_COMMAND"`.
|
|
385
|
+
|
|
386
|
+
If none of these help, open a [bug report](https://github.com/ysb3996-blip/oops/issues/new?template=bug_report.md) with the full `oops doctor` output (never a session log).
|
|
387
|
+
|
|
318
388
|
## Development
|
|
319
389
|
|
|
320
390
|
### Set up your machine
|
|
@@ -353,11 +423,11 @@ To try it as your shell does, build and install the gem into the Ruby you are us
|
|
|
353
423
|
|
|
354
424
|
```sh
|
|
355
425
|
gem build oops-cli.gemspec
|
|
356
|
-
gem install ./oops-cli-0.
|
|
426
|
+
gem install ./oops-cli-0.7.0.gem # the file name follows lib/oops/version.rb
|
|
357
427
|
rbenv rehash # only with rbenv
|
|
358
428
|
```
|
|
359
429
|
|
|
360
|
-
- A gem is installed per Ruby version. If a new tab uses another Ruby than the one you installed into (for example the repository pins 4.0.9, but your global Ruby is 3.3.5), the shell cannot find oops when it starts (bash prints `bash: oops: command not found`, zsh prints `command not found: oops`). Run `gem install` again under that Ruby, e.g. `RBENV_VERSION=3.3.5 gem install ./oops-cli-0.
|
|
430
|
+
- A gem is installed per Ruby version. If a new tab uses another Ruby than the one you installed into (for example the repository pins 4.0.9, but your global Ruby is 3.3.5), the shell cannot find oops when it starts (bash prints `bash: oops: command not found`, zsh prints `command not found: oops`). Run `gem install` again under that Ruby, e.g. `RBENV_VERSION=3.3.5 gem install ./oops-cli-0.7.0.gem`.
|
|
361
431
|
- Reinstall after every change. The installed gem is a copy, not a link to your checkout.
|
|
362
432
|
- To remove it: `gem uninstall oops-cli`.
|
|
363
433
|
- Put `eval "$(oops init zsh)"` in your rc file, not just at the prompt: the recorded shell reads the rc file again, and without the line it has no hooks (`oops doctor` shows `hooks: missing`).
|
|
@@ -375,7 +445,7 @@ Manual checklist before a release:
|
|
|
375
445
|
|
|
376
446
|
## Contributing
|
|
377
447
|
|
|
378
|
-
Bug reports, ideas and pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md); issues labeled `good first issue` are a good place to start. Every pull request must include the test and rubocop results and a check in a new terminal tab; see [What every pull request must include](CONTRIBUTING.md#what-every-pull-request-must-include).
|
|
448
|
+
Bug reports, ideas and pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md); issues labeled `good first issue` are a good place to start, and [New contributors: start here](https://github.com/ysb3996-blip/oops/issues/100) sorts them by size. Every pull request must include the test and rubocop results and a check in a new terminal tab; see [What every pull request must include](CONTRIBUTING.md#what-every-pull-request-must-include).
|
|
379
449
|
|
|
380
450
|
## Contributors
|
|
381
451
|
|
|
@@ -387,10 +457,12 @@ Thanks to everyone who has helped ([emoji key](https://allcontributors.org/docs/
|
|
|
387
457
|
<table>
|
|
388
458
|
<tbody>
|
|
389
459
|
<tr>
|
|
390
|
-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ysb3996-blip"><img src="https://avatars.githubusercontent.com/u/257992595?v=4
|
|
391
|
-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ricky9408"><img src="https://avatars.githubusercontent.com/u/49530170?v=4
|
|
392
|
-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/agenticsymphony-tech"><img src="https://avatars.githubusercontent.com/u/326739730?v=4
|
|
393
|
-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ShahadatTest"><img src="https://avatars.githubusercontent.com/u/179203101?v=4
|
|
460
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ysb3996-blip"><img src="https://avatars.githubusercontent.com/u/257992595?v=4&size=80" width="80px" height="80px" alt="ysb3996-blip"/><br /><sub><b>ysb3996-blip</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=ysb3996-blip" title="Code">💻</a> <a href="https://github.com/ysb3996-blip/oops/commits?author=ysb3996-blip" title="Documentation">📖</a> <a href="https://github.com/ysb3996-blip/oops/commits?author=ysb3996-blip" title="Tests">⚠️</a> <a href="#maintenance-ysb3996-blip" title="Maintenance">🚧</a></td>
|
|
461
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ricky9408"><img src="https://avatars.githubusercontent.com/u/49530170?v=4&size=80" width="80px" height="80px" alt="Sanghyuk Lee"/><br /><sub><b>Sanghyuk Lee</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=ricky9408" title="Code">💻</a></td>
|
|
462
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/agenticsymphony-tech"><img src="https://avatars.githubusercontent.com/u/326739730?v=4&size=80" width="80px" height="80px" alt="agenticsymphony-tech"/><br /><sub><b>agenticsymphony-tech</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=agenticsymphony-tech" title="Documentation">📖</a></td>
|
|
463
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ShahadatTest"><img src="https://avatars.githubusercontent.com/u/179203101?v=4&size=80" width="80px" height="80px" alt="ShahadatTest"/><br /><sub><b>ShahadatTest</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=ShahadatTest" title="Code">💻</a></td>
|
|
464
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/wolf4032"><img src="https://avatars.githubusercontent.com/u/144633223?v=4&size=80" width="80px" height="80px" alt="wolf4032"/><br /><sub><b>wolf4032</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=wolf4032" title="Documentation">📖</a></td>
|
|
465
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jdotc1"><img src="https://avatars.githubusercontent.com/u/138259519?v=4&size=80" width="80px" height="80px" alt="Jeff"/><br /><sub><b>Jeff</b></sub></a><br /><a href="https://github.com/ysb3996-blip/oops/commits?author=jdotc1" title="Code">💻</a></td>
|
|
394
466
|
</tr>
|
|
395
467
|
</tbody>
|
|
396
468
|
</table>
|
data/lib/oops/cli.rb
CHANGED
|
@@ -11,255 +11,323 @@ module Oops
|
|
|
11
11
|
|
|
12
12
|
NO_CLIPBOARD = "no clipboard tool found (tried pbcopy, wl-copy, xclip, xsel, clip.exe, OSC 52).".freeze
|
|
13
13
|
POSITIVE_INTEGER = /\A\d+\z/
|
|
14
|
-
CopyTarget = Data.define(:count, :failed_only)
|
|
14
|
+
CopyTarget = Data.define(:count, :failed_only, :pick)
|
|
15
15
|
COUNT_REPEATED = "specify the command count only once (N or -n)".freeze
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
# --json has its own shape, so the Markdown formatting options make no
|
|
18
|
+
# sense with it. --gist sends the text somewhere other than -p and --json
|
|
19
|
+
# do, and anyone with a secret gist's URL can read it, so it never carries
|
|
20
|
+
# unmasked secrets.
|
|
21
|
+
CONFLICTS = { json: %i[github time output_only], gist: %i[show_secrets print json] }.freeze
|
|
22
|
+
private_constant :CopyTarget, :COUNT_REPEATED, :CONFLICTS
|
|
17
23
|
|
|
18
24
|
def self.run(argv, env: ENV, stdin: $stdin, stdout: $stdout, stderr: $stderr)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
when "init" then return init(argv.drop(1), stdout: stdout, stderr: stderr)
|
|
22
|
-
when "doctor" then return doctor(argv.drop(1), env: env, stdin: stdin, stdout: stdout)
|
|
23
|
-
when "pause", "resume" then return toggle(argv.first, argv.drop(1), env: env, stdout: stdout)
|
|
24
|
-
when "status" then return status(argv.drop(1), env: env, stdout: stdout, stderr: stderr)
|
|
25
|
-
when "clear" then return clear(argv.drop(1), env: env, stdout: stdout)
|
|
26
|
-
end
|
|
25
|
+
App.new(env: env, stdin: stdin, stdout: stdout, stderr: stderr).run(argv)
|
|
26
|
+
end
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
# One run of the oops command. It holds the environment and the standard
|
|
29
|
+
# streams, so the subcommands take only their own arguments.
|
|
30
|
+
class App
|
|
31
|
+
def initialize(env:, stdin:, stdout:, stderr:)
|
|
32
|
+
@env = env
|
|
33
|
+
@stdin = stdin
|
|
34
|
+
@stdout = stdout
|
|
35
|
+
@stderr = stderr
|
|
36
|
+
end
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
o.on("-v", "--version", "Print version and exit") do
|
|
46
|
-
stdout.puts "oops #{VERSION}"
|
|
47
|
-
return 0
|
|
38
|
+
def run(argv)
|
|
39
|
+
case argv.first
|
|
40
|
+
when "record" then return record(argv.drop(1))
|
|
41
|
+
when "init" then return init(argv.drop(1))
|
|
42
|
+
when "doctor" then return doctor(argv.drop(1))
|
|
43
|
+
when "pause", "resume" then return toggle(argv.first, argv.drop(1))
|
|
44
|
+
when "status" then return status(argv.drop(1))
|
|
45
|
+
when "clear" then return clear(argv.drop(1))
|
|
48
46
|
end
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
|
|
48
|
+
options = { github: false, show_secrets: false, time: false, output_only: false, print: false,
|
|
49
|
+
json: false, gist: false }
|
|
50
|
+
count = nil
|
|
51
|
+
parser = OptionParser.new do |o|
|
|
52
|
+
o.banner = "Usage: oops [N | err | pick] [-n N] [options]\n " \
|
|
53
|
+
"oops init <shell> | pause | resume | status | clear [--all] | doctor"
|
|
54
|
+
o.on("-n N", "Copy the last N commands (with err, last N failures; with pick, list N)") do |v|
|
|
55
|
+
raise UsageError, COUNT_REPEATED if count
|
|
56
|
+
|
|
57
|
+
count = positive(v, "-n")
|
|
58
|
+
end
|
|
59
|
+
o.on("--github", "Format for a GitHub issue or PR comment") { options[:github] = true }
|
|
60
|
+
o.on("--time", "Add the time each command started") { options[:time] = true }
|
|
61
|
+
o.on("--output-only", "Leave out the command line, keep the output") { options[:output_only] = true }
|
|
62
|
+
o.on("--show-secrets", "Do not mask secrets or apply the replace table") { options[:show_secrets] = true }
|
|
63
|
+
o.on("-p", "--print", "Write the text to stdout instead of the clipboard") { options[:print] = true }
|
|
64
|
+
o.on("--json", "Write the commands as JSON to stdout") { options[:json] = true }
|
|
65
|
+
o.on("--gist", "Upload as a secret gist (needs gh) and copy its URL") { options[:gist] = true }
|
|
66
|
+
o.on("-v", "--version", "Print version and exit") do
|
|
67
|
+
stdout.puts "oops #{VERSION}"
|
|
68
|
+
return 0
|
|
69
|
+
end
|
|
70
|
+
o.on("-h", "--help", "Print this help and exit") do
|
|
71
|
+
stdout.puts o
|
|
72
|
+
return 0
|
|
73
|
+
end
|
|
52
74
|
end
|
|
75
|
+
copy_target = target(parser.parse(argv), count: count)
|
|
76
|
+
check_conflicts(options)
|
|
77
|
+
copy(copy_target, options)
|
|
78
|
+
rescue OptionParser::ParseError, UsageError => e
|
|
79
|
+
stderr.puts "oops: #{e.message}"
|
|
80
|
+
2
|
|
81
|
+
rescue Failure => e
|
|
82
|
+
stderr.puts "oops: #{e.message}"
|
|
83
|
+
1
|
|
53
84
|
end
|
|
54
|
-
copy_target = target(parser.parse(argv), count: count)
|
|
55
|
-
check_json(options)
|
|
56
|
-
copy(copy_target, options, env: env, stdout: stdout, stderr: stderr)
|
|
57
|
-
rescue OptionParser::ParseError, UsageError => e
|
|
58
|
-
stderr.puts "oops: #{e.message}"
|
|
59
|
-
2
|
|
60
|
-
rescue Failure => e
|
|
61
|
-
stderr.puts "oops: #{e.message}"
|
|
62
|
-
1
|
|
63
|
-
end
|
|
64
85
|
|
|
65
|
-
|
|
66
|
-
raise UsageError, "#{name} must be a positive integer" unless value.match?(POSITIVE_INTEGER) && value.to_i >= 1
|
|
86
|
+
private
|
|
67
87
|
|
|
68
|
-
|
|
69
|
-
end
|
|
88
|
+
attr_reader :env, :stdin, :stdout, :stderr
|
|
70
89
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def self.check_json(options)
|
|
74
|
-
return unless options[:json]
|
|
90
|
+
def positive(value, name)
|
|
91
|
+
raise UsageError, "#{name} must be a positive integer" unless value.match?(POSITIVE_INTEGER) && value.to_i >= 1
|
|
75
92
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
end
|
|
93
|
+
value.to_i
|
|
94
|
+
end
|
|
79
95
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
raise UsageError, "unexpected argument: #{args[1]}" if args.size > 1
|
|
96
|
+
def check_conflicts(options)
|
|
97
|
+
CONFLICTS.each do |option, others|
|
|
98
|
+
next unless options[option]
|
|
84
99
|
|
|
85
|
-
|
|
86
|
-
|
|
100
|
+
conflict = others.find { |key| options[key] }
|
|
101
|
+
raise UsageError, "--#{option} cannot be combined with #{flag(conflict)}" if conflict
|
|
102
|
+
end
|
|
103
|
+
end
|
|
87
104
|
|
|
88
|
-
|
|
89
|
-
raise UsageError, COUNT_REPEATED if count
|
|
105
|
+
def flag(key) = "--#{key.to_s.tr('_', '-')}"
|
|
90
106
|
|
|
91
|
-
|
|
92
|
-
|
|
107
|
+
# Count comes from either a positional N or -n N. "err" filters the
|
|
108
|
+
# selection to failed commands; without a count, one command is copied.
|
|
109
|
+
# "pick" lists the last count commands (Picker::COUNT by default) and
|
|
110
|
+
# copies the ones the user chooses.
|
|
111
|
+
def target(args, count:)
|
|
112
|
+
raise UsageError, "unexpected argument: #{args[1]}" if args.size > 1
|
|
93
113
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
114
|
+
arg = args.first
|
|
115
|
+
return CopyTarget.new(count: count || Picker::COUNT, failed_only: false, pick: true) if arg == "pick"
|
|
116
|
+
return CopyTarget.new(count: count || 1, failed_only: arg == "err", pick: false) if arg.nil? || arg == "err"
|
|
97
117
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
records = log.last(target.count, failed_only: target.failed_only)
|
|
101
|
-
raise Failure, (target.failed_only ? "no failed command found." : "no command found yet.") if records.empty?
|
|
118
|
+
raise UsageError, "unknown command: #{arg}" unless arg.match?(/\A[+-]?\d/)
|
|
119
|
+
raise UsageError, COUNT_REPEATED if count
|
|
102
120
|
|
|
103
|
-
|
|
104
|
-
formatter = Formatter.new(config: config, home: home, **options.except(:print, :json))
|
|
105
|
-
if options[:json]
|
|
106
|
-
stdout.write formatter.json(records)
|
|
107
|
-
return 0
|
|
121
|
+
CopyTarget.new(count: positive(arg, "N"), failed_only: false, pick: false)
|
|
108
122
|
end
|
|
109
123
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return 0
|
|
114
|
-
end
|
|
124
|
+
def copy(target, options)
|
|
125
|
+
log = recording_log
|
|
126
|
+
raise Failure, "recording is paused. Run oops resume first." if log.paused?
|
|
115
127
|
|
|
116
|
-
|
|
117
|
-
|
|
128
|
+
config = Config.load(env: env)
|
|
129
|
+
config.warnings.each { |w| stderr.puts "oops: warning: #{w}" }
|
|
130
|
+
records = log.last(target.count, failed_only: target.failed_only)
|
|
131
|
+
raise Failure, (target.failed_only ? "no failed command found." : "no command found yet.") if records.empty?
|
|
118
132
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
end
|
|
133
|
+
home = env["HOME"].to_s.empty? ? Dir.home : env["HOME"]
|
|
134
|
+
records = pick(records, config: config, home: home, show_secrets: options[:show_secrets]) if target.pick
|
|
135
|
+
formatter = Formatter.new(config: config, home: home, **options.except(:print, :json, :gist))
|
|
136
|
+
if options[:json]
|
|
137
|
+
stdout.write formatter.json(records)
|
|
138
|
+
return 0
|
|
139
|
+
end
|
|
127
140
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
rest ? "#{first} ..." : first.to_s
|
|
131
|
-
end
|
|
141
|
+
result = formatter.format(records)
|
|
142
|
+
return gist(result, config: config) if options[:gist]
|
|
132
143
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
144
|
+
if options[:print]
|
|
145
|
+
stdout.write result.text
|
|
146
|
+
return 0
|
|
147
|
+
end
|
|
137
148
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
raise Failure, "not recording in this shell. Add #{line} " \
|
|
150
|
-
"to #{rc} (after whatever puts oops's Ruby on PATH, as early as possible) " \
|
|
151
|
-
"and open a new tab."
|
|
152
|
-
end
|
|
149
|
+
backend = Clipboard.detect(config.clipboard, env: env)
|
|
150
|
+
raise Failure, NO_CLIPBOARD if backend.nil?
|
|
151
|
+
|
|
152
|
+
begin
|
|
153
|
+
backend.copy(result.text)
|
|
154
|
+
rescue Clipboard::Error => e
|
|
155
|
+
raise Failure, e.message
|
|
156
|
+
end
|
|
157
|
+
stdout.puts "copied: $ #{report_command(result.command_line)} (#{report_counts(result)})"
|
|
158
|
+
0
|
|
159
|
+
end
|
|
153
160
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
161
|
+
# `oops pick`: the list and the prompt go to stderr, so `oops pick -p`
|
|
162
|
+
# and `--json` keep stdout for the copied text. The answer is read from
|
|
163
|
+
# stdin, which also lets a script pipe the numbers in.
|
|
164
|
+
def pick(records, config:, home:, show_secrets:)
|
|
165
|
+
lister = Formatter.new(config: config, home: home, show_secrets: show_secrets)
|
|
166
|
+
stderr.puts Picker.menu(records, lister)
|
|
167
|
+
stderr.print "pick> "
|
|
168
|
+
stderr.flush
|
|
169
|
+
answer = stdin.gets
|
|
170
|
+
# A terminal echoes the answer and its newline; piped input does not.
|
|
171
|
+
stderr.puts unless stdin.tty?
|
|
172
|
+
records.values_at(*Picker.parse(answer, records.size).map { |n| n - 1 })
|
|
173
|
+
rescue Picker::Invalid => e
|
|
174
|
+
raise Failure, e.message
|
|
168
175
|
end
|
|
169
|
-
0
|
|
170
|
-
end
|
|
171
176
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
# The gist is made before the clipboard is tried, so a missing or failing
|
|
178
|
+
# clipboard only costs a warning: the URL is on stdout either way.
|
|
179
|
+
def gist(result, config:)
|
|
180
|
+
url = begin
|
|
181
|
+
Gist.create(result.text, description: "oops: $ #{report_command(result.command_line)}", env: env)
|
|
182
|
+
rescue Gist::Error => e
|
|
183
|
+
raise Failure, e.message
|
|
184
|
+
end
|
|
185
|
+
stdout.puts "gist: #{url} (#{report_counts(result)})"
|
|
179
186
|
begin
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
187
|
+
backend = Clipboard.detect(config.clipboard, env: env)
|
|
188
|
+
raise Clipboard::Error, NO_CLIPBOARD if backend.nil?
|
|
189
|
+
|
|
190
|
+
backend.copy(url)
|
|
191
|
+
rescue Clipboard::Error => e
|
|
192
|
+
stderr.puts "oops: warning: the URL was not copied: #{e.message}"
|
|
183
193
|
end
|
|
194
|
+
0
|
|
184
195
|
end
|
|
185
|
-
stdout.write marker
|
|
186
|
-
stdout.flush
|
|
187
|
-
end
|
|
188
196
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
def self.status(args, env:, stdout:, stderr:)
|
|
193
|
-
unless args.empty?
|
|
194
|
-
stderr.puts "oops: usage: oops status"
|
|
195
|
-
return 2
|
|
197
|
+
def report_command(command_line)
|
|
198
|
+
first, rest = command_line.to_s.split("\n", 2)
|
|
199
|
+
rest ? "#{first} ..." : first.to_s
|
|
196
200
|
end
|
|
197
201
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
end
|
|
203
|
-
stdout.puts word
|
|
204
|
-
word == "recording" ? 0 : 1
|
|
205
|
-
end
|
|
202
|
+
def report_counts(result)
|
|
203
|
+
counts = "#{result.lines} lines"
|
|
204
|
+
result.masked_count.positive? ? "#{counts}, #{result.masked_count} secrets masked" : counts
|
|
205
|
+
end
|
|
206
206
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
# The session log of the recorder this shell runs under. Raises Failure
|
|
208
|
+
# when there is none.
|
|
209
|
+
def recording_log
|
|
210
|
+
path = env["OOPS_SESSION"].to_s
|
|
211
|
+
return SessionLog.new(path) if !path.empty? && File.file?(path)
|
|
212
|
+
|
|
213
|
+
line, rc = case env["SHELL"].to_s
|
|
214
|
+
when /bash\z/ then [%(eval "$(oops init bash)"), "~/.bashrc"]
|
|
215
|
+
when /fish\z/ then ["oops init fish | source", "~/.config/fish/config.fish"]
|
|
216
|
+
else [%(eval "$(oops init zsh)"), "~/.zshrc"]
|
|
217
|
+
end
|
|
218
|
+
raise Failure, "not recording in this shell. Add #{line} " \
|
|
219
|
+
"to #{rc} (after whatever puts oops's Ruby on PATH, as early as possible) " \
|
|
220
|
+
"and open a new tab."
|
|
221
|
+
end
|
|
211
222
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
223
|
+
# `oops pause` / `oops resume`: the marker goes through the pty to the
|
|
224
|
+
# recorder; the flag file tells `oops` (and `doctor`) the state. The
|
|
225
|
+
# recorder only obeys a marker that agrees with the flag file, so the
|
|
226
|
+
# file changes first.
|
|
227
|
+
def toggle(name, args)
|
|
228
|
+
raise UsageError, "usage: oops #{name}" unless args.empty?
|
|
229
|
+
|
|
230
|
+
log = recording_log
|
|
231
|
+
if name == "pause"
|
|
232
|
+
log.pause!
|
|
233
|
+
write_marker(Marker.pause)
|
|
234
|
+
else
|
|
235
|
+
log.resume!
|
|
236
|
+
write_marker(Marker.resume)
|
|
237
|
+
end
|
|
238
|
+
0
|
|
239
|
+
end
|
|
217
240
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
241
|
+
# Like the shell hooks, write straight to the recorded terminal: with
|
|
242
|
+
# stdout redirected (`oops pause >/dev/null`) the recorder would never see
|
|
243
|
+
# the marker although the flag file already says "paused". Without a
|
|
244
|
+
# terminal that can be opened, stdout is used.
|
|
245
|
+
def write_marker(marker)
|
|
246
|
+
tty = env["OOPS_TTY"].to_s
|
|
247
|
+
unless tty.empty?
|
|
248
|
+
begin
|
|
249
|
+
return File.open(tty, File::WRONLY | File::NOCTTY) { |io| io.write(marker) }
|
|
250
|
+
rescue SystemCallError, IOError
|
|
251
|
+
nil
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
stdout.write marker
|
|
255
|
+
stdout.flush
|
|
221
256
|
end
|
|
222
|
-
stdout.puts "emptied this tab's log"
|
|
223
|
-
0
|
|
224
|
-
end
|
|
225
257
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
258
|
+
# `oops status`: one word on stdout. "recording" exits 0; "paused" and
|
|
259
|
+
# "off" (this shell is not recorded, or its log is gone) exit 1 without a
|
|
260
|
+
# message, so a prompt can call it.
|
|
261
|
+
def status(args)
|
|
262
|
+
unless args.empty?
|
|
263
|
+
stderr.puts "oops: usage: oops status"
|
|
264
|
+
return 2
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
path = env["OOPS_SESSION"].to_s
|
|
268
|
+
word = if path.empty? || !File.file?(path) then "off"
|
|
269
|
+
elsif SessionLog.new(path).paused? then "paused"
|
|
270
|
+
else "recording"
|
|
271
|
+
end
|
|
272
|
+
stdout.puts word
|
|
273
|
+
word == "recording" ? 0 : 1
|
|
274
|
+
end
|
|
229
275
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
rescue StandardError => e
|
|
235
|
-
raise if e.is_a?(UsageError)
|
|
276
|
+
# `oops clear [--all]`: deletes the logs of closed tabs; with --all, also
|
|
277
|
+
# empties this tab's log. Logs of other open tabs are never touched.
|
|
278
|
+
def clear(args)
|
|
279
|
+
raise UsageError, "usage: oops clear [--all]" unless args.empty? || args == ["--all"]
|
|
236
280
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
281
|
+
log = recording_log if args == ["--all"]
|
|
282
|
+
begin
|
|
283
|
+
removed = SessionLog.clear!(Paths.sessions_dir(env: env))
|
|
284
|
+
stdout.puts "removed #{removed} #{removed == 1 ? 'log' : 'logs'} of closed tabs"
|
|
285
|
+
return 0 unless log
|
|
240
286
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
287
|
+
log.empty!
|
|
288
|
+
rescue SystemCallError => e
|
|
289
|
+
raise Failure, "could not delete the logs: #{e.message}"
|
|
290
|
+
end
|
|
291
|
+
stdout.puts "emptied this tab's log"
|
|
292
|
+
0
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
# `oops doctor`: diagnostics on stdout; always exits 0.
|
|
296
|
+
def doctor(args)
|
|
297
|
+
raise UsageError, "usage: oops doctor" unless args.empty?
|
|
246
298
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
299
|
+
config = Config.load(env: env)
|
|
300
|
+
tty = Tty.name(stdin)
|
|
301
|
+
stdout.write Doctor.report(env: env, config: config, sessions_dir: Paths.sessions_dir(env: env), tty: tty)
|
|
302
|
+
0
|
|
303
|
+
rescue StandardError => e
|
|
304
|
+
raise if e.is_a?(UsageError)
|
|
305
|
+
|
|
306
|
+
stdout.puts "doctor: #{e.message}"
|
|
307
|
+
0
|
|
253
308
|
end
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
309
|
+
|
|
310
|
+
# `oops record [--] <shell> [args...]`
|
|
311
|
+
def record(args)
|
|
312
|
+
args = args.drop(1) if args.first == "--"
|
|
313
|
+
Recorder.new(args, env: env, stdin: stdin, stdout: stdout, stderr: stderr).run
|
|
257
314
|
end
|
|
258
|
-
stdout.write ShellInit.snippet(args.first, bin: File.expand_path($PROGRAM_NAME))
|
|
259
|
-
0
|
|
260
|
-
end
|
|
261
315
|
|
|
262
|
-
|
|
263
|
-
|
|
316
|
+
# `oops init zsh|bash|fish`: prints the snippet for `eval "$(oops init zsh)"`.
|
|
317
|
+
def init(args)
|
|
318
|
+
supported = ShellInit::SHELLS.join(", ")
|
|
319
|
+
if args.size != 1
|
|
320
|
+
stderr.puts "oops: usage: oops init <shell> (supported: #{supported})"
|
|
321
|
+
return 2
|
|
322
|
+
end
|
|
323
|
+
unless ShellInit::SHELLS.include?(args.first)
|
|
324
|
+
stderr.puts "oops: unsupported shell: #{args.first} (supported: #{supported})"
|
|
325
|
+
return 2
|
|
326
|
+
end
|
|
327
|
+
stdout.write ShellInit.snippet(args.first, bin: File.expand_path($PROGRAM_NAME))
|
|
328
|
+
0
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
private_constant :App
|
|
264
332
|
end
|
|
265
333
|
end
|
data/lib/oops/doctor.rb
CHANGED
|
@@ -53,8 +53,11 @@ module Oops
|
|
|
53
53
|
"shell: #{[shell, version].compact.join(' ')}, hooks: #{hooks}"
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
+
# Set by the init snippet: ZSH_VERSION, BASH_VERSION and fish's $version
|
|
57
|
+
# are shell parameters, never in the environment of a child process.
|
|
56
58
|
def shell_version(env)
|
|
57
|
-
|
|
59
|
+
version = env["__OOPS_SHELL_VERSION"].to_s
|
|
60
|
+
version.empty? ? nil : version
|
|
58
61
|
end
|
|
59
62
|
|
|
60
63
|
def clipboard_line(config, env, which)
|
data/lib/oops/gist.rb
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require "open3"
|
|
2
|
+
|
|
3
|
+
module Oops
|
|
4
|
+
# Uploads text as a secret gist through the GitHub CLI and returns its URL.
|
|
5
|
+
# oops never talks to GitHub or touches a token itself; gh does both.
|
|
6
|
+
module Gist
|
|
7
|
+
class Error < StandardError; end
|
|
8
|
+
|
|
9
|
+
FILENAME = "oops.md".freeze
|
|
10
|
+
# Seconds to wait for gh; it has to reach GitHub, so this is longer than
|
|
11
|
+
# the clipboard timeout.
|
|
12
|
+
TIMEOUT = 30
|
|
13
|
+
NO_GH = "--gist needs the GitHub CLI (gh). Install it from https://cli.github.com " \
|
|
14
|
+
"and run gh auth login once.".freeze
|
|
15
|
+
NOT_LOGGED_IN = "gh is not logged in to GitHub. Run gh auth login first.".freeze
|
|
16
|
+
|
|
17
|
+
module_function
|
|
18
|
+
|
|
19
|
+
# Returns the gist URL. Raises Error when gh is missing, not logged in,
|
|
20
|
+
# fails, times out or prints no URL. env supplies PATH for finding gh.
|
|
21
|
+
def create(text, description:, env: ENV, timeout: TIMEOUT)
|
|
22
|
+
argv = ["gh", "gist", "create", "-", "--filename", FILENAME, "--desc", description]
|
|
23
|
+
out, err, status = capture(argv, text, env, timeout)
|
|
24
|
+
raise Error, failure_message(err) unless status.success?
|
|
25
|
+
|
|
26
|
+
url = out.lines.map(&:strip).reverse.find { |line| line.start_with?("https://") }
|
|
27
|
+
raise Error, "gh gist create printed no URL" if url.nil?
|
|
28
|
+
|
|
29
|
+
url
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def capture(argv, text, env, timeout)
|
|
33
|
+
spawn_env = env["PATH"] ? { "PATH" => env["PATH"] } : {}
|
|
34
|
+
Open3.popen3(spawn_env, *argv, pgroup: true) do |stdin, stdout, stderr, wait|
|
|
35
|
+
readers = [Thread.new { stdout.read }, Thread.new { stderr.read }]
|
|
36
|
+
begin
|
|
37
|
+
stdin.write(text)
|
|
38
|
+
rescue Errno::EPIPE
|
|
39
|
+
nil
|
|
40
|
+
end
|
|
41
|
+
stdin.close
|
|
42
|
+
unless wait.join(timeout)
|
|
43
|
+
kill_group(wait.pid)
|
|
44
|
+
readers.each(&:kill)
|
|
45
|
+
raise Error, "gh timed out after #{timeout}s"
|
|
46
|
+
end
|
|
47
|
+
[readers[0].value.to_s, readers[1].value.to_s, wait.value]
|
|
48
|
+
end
|
|
49
|
+
rescue Errno::ENOENT
|
|
50
|
+
raise Error, NO_GH
|
|
51
|
+
rescue SystemCallError, IOError => e
|
|
52
|
+
raise Error, "gh: #{e.message}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def kill_group(pid)
|
|
56
|
+
Process.kill("KILL", -pid)
|
|
57
|
+
rescue SystemCallError
|
|
58
|
+
nil
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# gh asks for `gh auth login` when it has no usable token. Otherwise the
|
|
62
|
+
# last line of its stderr holds the error; earlier lines are progress.
|
|
63
|
+
def failure_message(err)
|
|
64
|
+
return NOT_LOGGED_IN if err.match?(/gh auth login/)
|
|
65
|
+
|
|
66
|
+
last = err.lines.map(&:strip).reject(&:empty?).last
|
|
67
|
+
last ? "gh gist create failed: #{last}" : "gh gist create failed"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private_class_method :capture, :kill_group, :failure_message
|
|
71
|
+
end
|
|
72
|
+
end
|
data/lib/oops/picker.rb
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module Oops
|
|
2
|
+
# The numbered list that `oops pick` shows, and what the user types back.
|
|
3
|
+
# Numbers run from 1 (oldest) so the newest command sits next to the prompt.
|
|
4
|
+
module Picker
|
|
5
|
+
class Invalid < StandardError; end
|
|
6
|
+
|
|
7
|
+
# Default number of commands listed.
|
|
8
|
+
COUNT = 10
|
|
9
|
+
# Long commands are cut so each entry stays on one terminal line.
|
|
10
|
+
COMMAND_WIDTH = 60
|
|
11
|
+
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
# One line per record. formatter cleans and masks the command line the
|
|
15
|
+
# same way the copied text is, so a token never shows up in the list.
|
|
16
|
+
def menu(records, formatter)
|
|
17
|
+
digits = records.size.to_s.size
|
|
18
|
+
rows = records.map do |record|
|
|
19
|
+
result = formatter.format([record])
|
|
20
|
+
[short(result.command_line), details(record, result.lines)]
|
|
21
|
+
end
|
|
22
|
+
width = rows.map { |command, _| command.size }.max
|
|
23
|
+
rows.each_with_index.map do |(command, details), i|
|
|
24
|
+
"#{(i + 1).to_s.rjust(digits)} $ #{command.ljust(width)} (#{details})"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Numbers, ranges (2-4) or both, separated by spaces or commas. Returns
|
|
29
|
+
# the chosen positions (1-based), sorted and without repeats, so the copy
|
|
30
|
+
# keeps the order the commands ran in. Raises Invalid otherwise.
|
|
31
|
+
def parse(input, size)
|
|
32
|
+
tokens = input.to_s.split(/[\s,]+/).reject(&:empty?)
|
|
33
|
+
raise Invalid, "nothing picked." if tokens.empty?
|
|
34
|
+
|
|
35
|
+
tokens.flat_map { |token| positions(token, size) }.uniq.sort
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def positions(token, size)
|
|
39
|
+
first, last = token.match(/\A(\d+)(?:-(\d+))?\z/)&.captures
|
|
40
|
+
raise Invalid, "not a number: #{token}" unless first
|
|
41
|
+
|
|
42
|
+
range = first.to_i..(last || first).to_i
|
|
43
|
+
bad = [range.begin, range.end].find { |n| n < 1 || n > size }
|
|
44
|
+
raise Invalid, "no command numbered #{bad} (1-#{size})" if bad
|
|
45
|
+
raise Invalid, "backwards range: #{token}" if range.none?
|
|
46
|
+
|
|
47
|
+
range.to_a
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def short(command)
|
|
51
|
+
first, rest = command.to_s.split("\n", 2)
|
|
52
|
+
first = first.to_s
|
|
53
|
+
first = "#{first[0, COMMAND_WIDTH - 3]}..." if first.size > COMMAND_WIDTH
|
|
54
|
+
rest ? "#{first} ..." : first
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def details(record, lines)
|
|
58
|
+
parts = ["exit #{record.exit}", "#{lines} #{lines == 1 ? 'line' : 'lines'}"]
|
|
59
|
+
parts << Time.at(record.started_at.to_i).strftime("%H:%M") if record.started_at
|
|
60
|
+
parts.join(", ")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private_class_method :positions, :short, :details
|
|
64
|
+
end
|
|
65
|
+
end
|
data/lib/oops/secrets.rb
CHANGED
|
@@ -17,6 +17,7 @@ module Oops
|
|
|
17
17
|
/\bsk-[A-Za-z0-9_-]{20,}/, # OpenAI / Anthropic keys
|
|
18
18
|
/\b[sr]k_(?:live|test)_[A-Za-z0-9]{16,}/, # Stripe secret keys
|
|
19
19
|
/\bglpat-[A-Za-z0-9_-]{20,}/, # GitLab tokens
|
|
20
|
+
/(?<![A-Za-z0-9_])(?:dop|doo|dor)_v1_[0-9a-f]{64}(?![A-Za-z0-9_])/, # DigitalOcean API tokens
|
|
20
21
|
/\bAIza[0-9A-Za-z_-]{35}/, # Google API keys
|
|
21
22
|
/\bnpm_[A-Za-z0-9]{36}/, # npm tokens
|
|
22
23
|
%r{hooks\.slack\.com/services/(?<secret>[A-Za-z0-9/]+)}, # Slack webhook URLs
|
data/lib/oops/shell/oops.bash
CHANGED
|
@@ -335,6 +335,8 @@ if [[ $- == *i* ]] && [ -t 0 ] && [ -t 1 ] && [ -z "${OOPS_DISABLE:-}" ] &&
|
|
|
335
335
|
# Exported so a nested shell on this tty continues the numbering.
|
|
336
336
|
export __OOPS_SEQ
|
|
337
337
|
export __OOPS_PID=$$
|
|
338
|
+
# Shell parameters are not exported; oops doctor reads this one.
|
|
339
|
+
export __OOPS_SHELL_VERSION=$BASH_VERSION
|
|
338
340
|
fi
|
|
339
341
|
if __oops_bp_present; then
|
|
340
342
|
__oops_use_bp
|
data/lib/oops/shell/oops.fish
CHANGED
|
@@ -86,6 +86,8 @@ if status is-interactive; and test -t 1; and test -t 2; and not set -q OOPS_DISA
|
|
|
86
86
|
# Exported so a nested shell on this tty continues the numbering.
|
|
87
87
|
set -gx __OOPS_SEQ $__OOPS_SEQ
|
|
88
88
|
set -gx __OOPS_PID $fish_pid
|
|
89
|
+
# $version is not exported; oops doctor reads this one.
|
|
90
|
+
set -gx __OOPS_SHELL_VERSION $version
|
|
89
91
|
end
|
|
90
92
|
|
|
91
93
|
# The shell this one replaced had Ghostty's integration (see above);
|
data/lib/oops/shell/oops.zsh
CHANGED
|
@@ -86,6 +86,8 @@ if [[ -o interactive && -t 0 && -t 1 && -n "${TTY:-}" && -z "${OOPS_DISABLE:-}"
|
|
|
86
86
|
# Exported so a nested shell on this tty continues the numbering.
|
|
87
87
|
export __OOPS_SEQ
|
|
88
88
|
export __OOPS_PID=$$
|
|
89
|
+
# Shell parameters are not exported; oops doctor reads this one.
|
|
90
|
+
export __OOPS_SHELL_VERSION=$ZSH_VERSION
|
|
89
91
|
fi
|
|
90
92
|
add-zsh-hook preexec __oops_preexec
|
|
91
93
|
add-zsh-hook precmd __oops_precmd
|
data/lib/oops/version.rb
CHANGED
data/lib/oops.rb
CHANGED
|
@@ -7,11 +7,13 @@ require_relative "oops/tty"
|
|
|
7
7
|
require_relative "oops/config"
|
|
8
8
|
require_relative "oops/prompt_sp"
|
|
9
9
|
require_relative "oops/formatter"
|
|
10
|
+
require_relative "oops/picker"
|
|
10
11
|
require_relative "oops/session_log"
|
|
11
12
|
require_relative "oops/marker"
|
|
12
13
|
require_relative "oops/stream_parser"
|
|
13
14
|
require_relative "oops/recorder"
|
|
14
15
|
require_relative "oops/shell_init"
|
|
15
16
|
require_relative "oops/clipboard"
|
|
17
|
+
require_relative "oops/gist"
|
|
16
18
|
require_relative "oops/doctor"
|
|
17
19
|
require_relative "oops/cli"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: oops-cli
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ysb3996-blip
|
|
@@ -32,8 +32,10 @@ files:
|
|
|
32
32
|
- lib/oops/config.rb
|
|
33
33
|
- lib/oops/doctor.rb
|
|
34
34
|
- lib/oops/formatter.rb
|
|
35
|
+
- lib/oops/gist.rb
|
|
35
36
|
- lib/oops/marker.rb
|
|
36
37
|
- lib/oops/paths.rb
|
|
38
|
+
- lib/oops/picker.rb
|
|
37
39
|
- lib/oops/prompt_sp.rb
|
|
38
40
|
- lib/oops/record.rb
|
|
39
41
|
- lib/oops/recorder.rb
|