oops-cli 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ed6df7dbb48f2a4e9b8674e2cf787b7fbccdc8367384d13cce77c37be7eacda
4
- data.tar.gz: 5088e40547ff5e638ecb58795f31829e8ce7eb845834bff1b8a6117eae986144
3
+ metadata.gz: c24a418f8fcaabcf3565ae05b07c5dfe1a87ec57f3f3b8ac18c506d083b6fe7c
4
+ data.tar.gz: ffb48126a7abf9e885ed05a1e9c8c14259dd5ca3e33d9cfd17fdd07284e36add
5
5
  SHA512:
6
- metadata.gz: a6a1600cc3030eacb11c1b6931ad730a1d17870651eb92359b008c6fe4292dea8c00248093e5347729eb5b833d5955fe834fe8c078ef62025be8611a036d75ee
7
- data.tar.gz: c4c069c81d9188d769e6dfcae78a1ec19273fe6f512dec9b0b321230c23c855e60442d773bb2af7212eaaf1e026d73328a02ebcd10289a59e71fbcf6c7c4000e
6
+ metadata.gz: 5033b91ba56b64eb0967f7203be4f68d7a6d067ee5a62b89094ae0c9e2be494ea14870a2f71e1780ec9c17b0ea5c9650855f1a20dfa0e72503de7599c4229959
7
+ data.tar.gz: 16a676598e4f17ae7f9610445f8abb91fede0902c89c7aa417151c6c6eb8598664f96674a8bf2a34605cf0cf99ae28d4b60c28e5b8da6e2a35220767c83e2a60
data/CHANGELOG.ja.md CHANGED
@@ -2,6 +2,13 @@
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
+
5
12
  ## 0.6.0 - 2026-11-10
6
13
 
7
14
  - 追加: `--gist` で、整えた文字列を GitHub CLI(`gh gist create`)経由で secret gist に上げ、その URL をコピーします。秘密情報は必ずマスクし、`--show-secrets`・`--print`・`--json` との併用は使い方の誤りになります([#44](https://github.com/ysb3996-blip/oops/issues/44))。
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
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
+
5
12
  ## 0.6.0 - 2026-11-10
6
13
 
7
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)).
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,11 +127,11 @@ 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` | `$ コマンド` の行を省き、出力だけをコピーする |
@@ -131,7 +144,7 @@ oops init fish | source
131
144
 
132
145
  `oops` 自身はコピー対象になりません。直前のコマンドが `oops` だった場合は、その前のコマンドがコピーされます。
133
146
 
134
- 終了コード: `0` コピーした(または `--print`・`--json` で出力した、`--gist` で上げた)、`1` コピーしなかった(記録していない、まだコマンドがない、失敗したコマンドがない、一時停止中、クリップボードのコマンドが失敗、`--gist` で `gh` が失敗)、`2` 使い方の誤り。
147
+ 終了コード: `0` コピーした(または `--print`・`--json` で出力した、`--gist` で上げた)、`1` コピーしなかった(記録していない、まだコマンドがない、失敗したコマンドがない、何も選ばなかった、一時停止中、クリップボードのコマンドが失敗、`--gist` で `gh` が失敗)、`2` 使い方の誤り。
135
148
 
136
149
  ### 標準の出力
137
150
 
@@ -220,6 +233,21 @@ oops 自身は GitHub とやり取りしません。[GitHub CLI](https://cli.git
220
233
 
221
234
  secret gist は一覧にも検索にも出ませんが、URL を知っていれば誰でも開けます。そのため秘密情報は必ずマスクします。`--show-secrets` を `--gist` と併用すると使い方の誤りになり、`--print`・`--json` との併用も同じです。要らなくなった gist は、gist.github.com か `gh gist delete` で消してください。クリップボードのツールが見つからないときも URL は表示し、コピーできなかったことを警告します。
222
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
+
223
251
  ### `oops status`
224
252
 
225
253
  `oops status` は `recording`・`paused`・`off`(このシェルが記録されていない、またはログが削除された)のどれかを出力し、記録中のときだけ終了コード `0` を返します。エラーは出さないので、プロンプトやスクリプトから呼べます(例: [starship のカスタムモジュール](https://starship.rs/config/#custom-commands))。呼ぶたびに Ruby が起動するため 0.1〜0.2 秒ほどかかります。`off` のときの詳しい理由は `oops doctor` で分かります。
@@ -395,11 +423,11 @@ bundle exec exe/oops doctor
395
423
 
396
424
  ```sh
397
425
  gem build oops-cli.gemspec
398
- gem install ./oops-cli-0.6.0.gem # ファイル名は lib/oops/version.rb に合わせる
426
+ gem install ./oops-cli-0.7.0.gem # ファイル名は lib/oops/version.rb に合わせる
399
427
  rbenv rehash # rbenv を使う場合のみ
400
428
  ```
401
429
 
402
- - 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.6.0.gem`)。
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`)。
403
431
  - 変更のたびに入れ直してください。インストールされた gem はコピーで、チェックアウトへのリンクではありません。
404
432
  - 削除するには `gem uninstall oops-cli` です。
405
433
  - `eval "$(oops init zsh)"` は、プロンプトで打つだけでなく rc ファイルに書いてください。記録されるシェルは rc ファイルを読み直すため、行がないとフックが入りません(`oops doctor` に `hooks: missing` と出ます)。
@@ -417,7 +445,7 @@ rbenv rehash # rbenv を使う場合のみ
417
445
 
418
446
  ## コントリビュート
419
447
 
420
- バグ報告、アイデア、プルリクエストを歓迎します。[CONTRIBUTING.ja.md](CONTRIBUTING.ja.md) を読んでください。`good first issue` のラベルが付いた issue が、始めやすい入口です。プルリクエストには、テストと rubocop の結果、新しいタブでの動作確認を必ず貼ってください([プルリクエストに必ず貼るもの](CONTRIBUTING.ja.md#プルリクエストに必ず貼るもの))。
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#プルリクエストに必ず貼るもの))。
421
449
 
422
450
  ## 貢献してくれた人たち
423
451
 
@@ -429,11 +457,12 @@ rbenv rehash # rbenv を使う場合のみ
429
457
  <table>
430
458
  <tbody>
431
459
  <tr>
432
- <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?s=80" width="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>
433
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/ricky9408"><img src="https://avatars.githubusercontent.com/u/49530170?v=4?s=80" width="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>
434
- <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?s=80" width="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>
435
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/ShahadatTest"><img src="https://avatars.githubusercontent.com/u/179203101?v=4?s=80" width="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>
436
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/wolf4032"><img src="https://avatars.githubusercontent.com/u/144633223?v=4?s=80" width="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>
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>
437
466
  </tr>
438
467
  </tbody>
439
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,11 +127,11 @@ 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 err`:
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 |
@@ -131,7 +144,7 @@ Options for `oops`, `oops N` and `oops err`:
131
144
 
132
145
  `oops` never copies itself: if the previous command was `oops`, you get the command before it.
133
146
 
134
- 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, paused, the clipboard command failed, or `gh` failed with `--gist`), `2` usage error.
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.
135
148
 
136
149
  ### Default output
137
150
 
@@ -220,6 +233,21 @@ oops does not talk to GitHub itself: it runs `gh gist create` from the [GitHub C
220
233
 
221
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.
222
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
+
223
251
  ### `oops status`
224
252
 
225
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`.
@@ -395,11 +423,11 @@ To try it as your shell does, build and install the gem into the Ruby you are us
395
423
 
396
424
  ```sh
397
425
  gem build oops-cli.gemspec
398
- gem install ./oops-cli-0.6.0.gem # the file name follows lib/oops/version.rb
426
+ gem install ./oops-cli-0.7.0.gem # the file name follows lib/oops/version.rb
399
427
  rbenv rehash # only with rbenv
400
428
  ```
401
429
 
402
- - 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.6.0.gem`.
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`.
403
431
  - Reinstall after every change. The installed gem is a copy, not a link to your checkout.
404
432
  - To remove it: `gem uninstall oops-cli`.
405
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`).
@@ -417,7 +445,7 @@ Manual checklist before a release:
417
445
 
418
446
  ## Contributing
419
447
 
420
- 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).
421
449
 
422
450
  ## Contributors
423
451
 
@@ -429,11 +457,12 @@ Thanks to everyone who has helped ([emoji key](https://allcontributors.org/docs/
429
457
  <table>
430
458
  <tbody>
431
459
  <tr>
432
- <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?s=80" width="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>
433
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/ricky9408"><img src="https://avatars.githubusercontent.com/u/49530170?v=4?s=80" width="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>
434
- <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?s=80" width="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>
435
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/ShahadatTest"><img src="https://avatars.githubusercontent.com/u/179203101?v=4?s=80" width="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>
436
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/wolf4032"><img src="https://avatars.githubusercontent.com/u/144633223?v=4?s=80" width="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>
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>
437
466
  </tr>
438
467
  </tbody>
439
468
  </table>
data/lib/oops/cli.rb CHANGED
@@ -11,287 +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
- private_constant :CopyTarget, :COUNT_REPEATED
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
- case argv.first
20
- when "record" then return record(argv.drop(1), env: env, stdin: stdin, stdout: stdout, stderr: stderr)
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
- options = { github: false, show_secrets: false, time: false, output_only: false, print: false,
29
- json: false, gist: false }
30
- count = nil
31
- parser = OptionParser.new do |o|
32
- o.banner = "Usage: oops [N | err] [-n N] [options]\n " \
33
- "oops init <shell> | pause | resume | status | clear [--all] | doctor"
34
- o.on("-n N", "Copy the last N commands (with err, last N failures)") do |v|
35
- raise UsageError, COUNT_REPEATED if count
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
- count = positive(v, "-n")
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))
38
46
  end
39
- o.on("--github", "Format for a GitHub issue or PR comment") { options[:github] = true }
40
- o.on("--time", "Add the time each command started") { options[:time] = true }
41
- o.on("--output-only", "Leave out the command line, keep the output") { options[:output_only] = true }
42
- o.on("--show-secrets", "Do not mask secrets or apply the replace table") { options[:show_secrets] = true }
43
- o.on("-p", "--print", "Write the text to stdout instead of the clipboard") { options[:print] = true }
44
- o.on("--json", "Write the commands as JSON to stdout") { options[:json] = true }
45
- o.on("--gist", "Upload as a secret gist (needs gh) and copy its URL") { options[:gist] = true }
46
- o.on("-v", "--version", "Print version and exit") do
47
- stdout.puts "oops #{VERSION}"
48
- return 0
49
- end
50
- o.on("-h", "--help", "Print this help and exit") do
51
- stdout.puts o
52
- return 0
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
53
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
54
84
  end
55
- copy_target = target(parser.parse(argv), count: count)
56
- check_conflicts(options)
57
- copy(copy_target, options, env: env, stdout: stdout, stderr: stderr)
58
- rescue OptionParser::ParseError, UsageError => e
59
- stderr.puts "oops: #{e.message}"
60
- 2
61
- rescue Failure => e
62
- stderr.puts "oops: #{e.message}"
63
- 1
64
- end
65
85
 
66
- def self.positive(value, name)
67
- raise UsageError, "#{name} must be a positive integer" unless value.match?(POSITIVE_INTEGER) && value.to_i >= 1
86
+ private
68
87
 
69
- value.to_i
70
- end
88
+ attr_reader :env, :stdin, :stdout, :stderr
71
89
 
72
- # --json has its own shape, so the Markdown formatting options make no
73
- # sense with it. --gist sends the text somewhere other than -p and --json
74
- # do, and anyone with a secret gist's URL can read it, so it never carries
75
- # unmasked secrets.
76
- CONFLICTS = { json: %i[github time output_only], gist: %i[show_secrets print json] }.freeze
77
- private_constant :CONFLICTS
90
+ def positive(value, name)
91
+ raise UsageError, "#{name} must be a positive integer" unless value.match?(POSITIVE_INTEGER) && value.to_i >= 1
92
+
93
+ value.to_i
94
+ end
78
95
 
79
- def self.check_conflicts(options)
80
- CONFLICTS.each do |option, others|
81
- next unless options[option]
96
+ def check_conflicts(options)
97
+ CONFLICTS.each do |option, others|
98
+ next unless options[option]
82
99
 
83
- conflict = others.find { |key| options[key] }
84
- raise UsageError, "--#{option} cannot be combined with #{flag(conflict)}" if conflict
100
+ conflict = others.find { |key| options[key] }
101
+ raise UsageError, "--#{option} cannot be combined with #{flag(conflict)}" if conflict
102
+ end
85
103
  end
86
- end
87
104
 
88
- def self.flag(key) = "--#{key.to_s.tr('_', '-')}"
105
+ def flag(key) = "--#{key.to_s.tr('_', '-')}"
89
106
 
90
- # Count comes from either a positional N or -n N. "err" filters the
91
- # selection to failed commands; without a count, one command is copied.
92
- def self.target(args, count:)
93
- raise UsageError, "unexpected argument: #{args[1]}" if args.size > 1
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
94
113
 
95
- arg = args.first
96
- return CopyTarget.new(count: count || 1, failed_only: arg == "err") if arg.nil? || arg == "err"
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
- raise UsageError, "unknown command: #{arg}" unless arg.match?(/\A[+-]?\d/)
99
- raise UsageError, COUNT_REPEATED if count
118
+ raise UsageError, "unknown command: #{arg}" unless arg.match?(/\A[+-]?\d/)
119
+ raise UsageError, COUNT_REPEATED if count
100
120
 
101
- CopyTarget.new(count: positive(arg, "N"), failed_only: false)
102
- end
121
+ CopyTarget.new(count: positive(arg, "N"), failed_only: false, pick: false)
122
+ end
103
123
 
104
- def self.copy(target, options, env:, stdout:, stderr:)
105
- log = recording_log(env)
106
- raise Failure, "recording is paused. Run oops resume first." if log.paused?
124
+ def copy(target, options)
125
+ log = recording_log
126
+ raise Failure, "recording is paused. Run oops resume first." if log.paused?
107
127
 
108
- config = Config.load(env: env)
109
- config.warnings.each { |w| stderr.puts "oops: warning: #{w}" }
110
- records = log.last(target.count, failed_only: target.failed_only)
111
- raise Failure, (target.failed_only ? "no failed command found." : "no command found yet.") if records.empty?
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?
112
132
 
113
- home = env["HOME"].to_s.empty? ? Dir.home : env["HOME"]
114
- formatter = Formatter.new(config: config, home: home, **options.except(:print, :json, :gist))
115
- if options[:json]
116
- stdout.write formatter.json(records)
117
- return 0
118
- 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
119
140
 
120
- result = formatter.format(records)
121
- return gist(result, config: config, env: env, stdout: stdout, stderr: stderr) if options[:gist]
141
+ result = formatter.format(records)
142
+ return gist(result, config: config) if options[:gist]
122
143
 
123
- if options[:print]
124
- stdout.write result.text
125
- return 0
126
- end
144
+ if options[:print]
145
+ stdout.write result.text
146
+ return 0
147
+ end
127
148
 
128
- backend = Clipboard.detect(config.clipboard, env: env)
129
- raise Failure, NO_CLIPBOARD if backend.nil?
149
+ backend = Clipboard.detect(config.clipboard, env: env)
150
+ raise Failure, NO_CLIPBOARD if backend.nil?
130
151
 
131
- begin
132
- backend.copy(result.text)
133
- rescue Clipboard::Error => e
134
- raise Failure, e.message
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
135
159
  end
136
- stdout.puts "copied: $ #{report_command(result.command_line)} (#{report_counts(result)})"
137
- 0
138
- end
139
160
 
140
- # The gist is made before the clipboard is tried, so a missing or failing
141
- # clipboard only costs a warning: the URL is on stdout either way.
142
- def self.gist(result, config:, env:, stdout:, stderr:)
143
- url = begin
144
- Gist.create(result.text, description: "oops: $ #{report_command(result.command_line)}", env: env)
145
- rescue Gist::Error => e
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
146
174
  raise Failure, e.message
147
175
  end
148
- stdout.puts "gist: #{url} (#{report_counts(result)})"
149
- begin
150
- backend = Clipboard.detect(config.clipboard, env: env)
151
- raise Clipboard::Error, NO_CLIPBOARD if backend.nil?
152
176
 
153
- backend.copy(url)
154
- rescue Clipboard::Error => e
155
- stderr.puts "oops: warning: the URL was not copied: #{e.message}"
156
- end
157
- 0
158
- end
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)})"
186
+ begin
187
+ backend = Clipboard.detect(config.clipboard, env: env)
188
+ raise Clipboard::Error, NO_CLIPBOARD if backend.nil?
159
189
 
160
- def self.report_command(command_line)
161
- first, rest = command_line.to_s.split("\n", 2)
162
- rest ? "#{first} ..." : first.to_s
163
- end
190
+ backend.copy(url)
191
+ rescue Clipboard::Error => e
192
+ stderr.puts "oops: warning: the URL was not copied: #{e.message}"
193
+ end
194
+ 0
195
+ end
164
196
 
165
- def self.report_counts(result)
166
- counts = "#{result.lines} lines"
167
- result.masked_count.positive? ? "#{counts}, #{result.masked_count} secrets masked" : counts
168
- end
197
+ def report_command(command_line)
198
+ first, rest = command_line.to_s.split("\n", 2)
199
+ rest ? "#{first} ..." : first.to_s
200
+ end
169
201
 
170
- # The session log of the recorder this shell runs under. Raises Failure
171
- # when there is none.
172
- def self.recording_log(env)
173
- path = env["OOPS_SESSION"].to_s
174
- return SessionLog.new(path) if !path.empty? && File.file?(path)
175
-
176
- line, rc = case env["SHELL"].to_s
177
- when /bash\z/ then [%(eval "$(oops init bash)"), "~/.bashrc"]
178
- when /fish\z/ then ["oops init fish | source", "~/.config/fish/config.fish"]
179
- else [%(eval "$(oops init zsh)"), "~/.zshrc"]
180
- end
181
- raise Failure, "not recording in this shell. Add #{line} " \
182
- "to #{rc} (after whatever puts oops's Ruby on PATH, as early as possible) " \
183
- "and open a new tab."
184
- 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
185
206
 
186
- # `oops pause` / `oops resume`: the marker goes through the pty to the
187
- # recorder; the flag file tells `oops` (and `doctor`) the state. The
188
- # recorder only obeys a marker that agrees with the flag file, so the
189
- # file changes first.
190
- def self.toggle(name, args, env:, stdout:)
191
- raise UsageError, "usage: oops #{name}" unless args.empty?
192
-
193
- log = recording_log(env)
194
- if name == "pause"
195
- log.pause!
196
- write_marker(Marker.pause, env: env, stdout: stdout)
197
- else
198
- log.resume!
199
- write_marker(Marker.resume, env: env, stdout: stdout)
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."
200
221
  end
201
- 0
202
- end
203
222
 
204
- # Like the shell hooks, write straight to the recorded terminal: with
205
- # stdout redirected (`oops pause >/dev/null`) the recorder would never see
206
- # the marker although the flag file already says "paused". Without a
207
- # terminal that can be opened, stdout is used.
208
- def self.write_marker(marker, env:, stdout:)
209
- tty = env["OOPS_TTY"].to_s
210
- unless tty.empty?
211
- begin
212
- return File.open(tty, File::WRONLY | File::NOCTTY) { |io| io.write(marker) }
213
- rescue SystemCallError, IOError
214
- nil
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)
215
237
  end
238
+ 0
216
239
  end
217
- stdout.write marker
218
- stdout.flush
219
- end
220
240
 
221
- # `oops status`: one word on stdout. "recording" exits 0; "paused" and
222
- # "off" (this shell is not recorded, or its log is gone) exit 1 without a
223
- # message, so a prompt can call it.
224
- def self.status(args, env:, stdout:, stderr:)
225
- unless args.empty?
226
- stderr.puts "oops: usage: oops status"
227
- return 2
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
228
256
  end
229
257
 
230
- path = env["OOPS_SESSION"].to_s
231
- word = if path.empty? || !File.file?(path) then "off"
232
- elsif SessionLog.new(path).paused? then "paused"
233
- else "recording"
234
- end
235
- stdout.puts word
236
- word == "recording" ? 0 : 1
237
- end
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
238
266
 
239
- # `oops clear [--all]`: deletes the logs of closed tabs; with --all, also
240
- # empties this tab's log. Logs of other open tabs are never touched.
241
- def self.clear(args, env:, stdout:)
242
- raise UsageError, "usage: oops clear [--all]" unless args.empty? || args == ["--all"]
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
243
275
 
244
- log = recording_log(env) if args == ["--all"]
245
- begin
246
- removed = SessionLog.clear!(Paths.sessions_dir(env: env))
247
- stdout.puts "removed #{removed} #{removed == 1 ? 'log' : 'logs'} of closed tabs"
248
- return 0 unless log
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"]
249
280
 
250
- log.empty!
251
- rescue SystemCallError => e
252
- raise Failure, "could not delete the logs: #{e.message}"
253
- end
254
- stdout.puts "emptied this tab's log"
255
- 0
256
- end
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
257
286
 
258
- # `oops doctor`: diagnostics on stdout; always exits 0.
259
- def self.doctor(args, env:, stdin:, stdout:)
260
- raise UsageError, "usage: oops doctor" unless args.empty?
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
261
294
 
262
- config = Config.load(env: env)
263
- tty = Tty.name(stdin)
264
- stdout.write Doctor.report(env: env, config: config, sessions_dir: Paths.sessions_dir(env: env), tty: tty)
265
- 0
266
- rescue StandardError => e
267
- raise if e.is_a?(UsageError)
295
+ # `oops doctor`: diagnostics on stdout; always exits 0.
296
+ def doctor(args)
297
+ raise UsageError, "usage: oops doctor" unless args.empty?
268
298
 
269
- stdout.puts "doctor: #{e.message}"
270
- 0
271
- end
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)
272
305
 
273
- # `oops record [--] <shell> [args...]`
274
- def self.record(args, env:, stdin:, stdout:, stderr:)
275
- args = args.drop(1) if args.first == "--"
276
- Recorder.new(args, env: env, stdin: stdin, stdout: stdout, stderr: stderr).run
277
- end
306
+ stdout.puts "doctor: #{e.message}"
307
+ 0
308
+ end
278
309
 
279
- # `oops init zsh|bash|fish`: prints the snippet for `eval "$(oops init zsh)"`.
280
- def self.init(args, stdout:, stderr:)
281
- supported = ShellInit::SHELLS.join(", ")
282
- if args.size != 1
283
- stderr.puts "oops: usage: oops init <shell> (supported: #{supported})"
284
- return 2
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
285
314
  end
286
- unless ShellInit::SHELLS.include?(args.first)
287
- stderr.puts "oops: unsupported shell: #{args.first} (supported: #{supported})"
288
- return 2
315
+
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
289
329
  end
290
- stdout.write ShellInit.snippet(args.first, bin: File.expand_path($PROGRAM_NAME))
291
- 0
292
330
  end
293
-
294
- private_class_method :positive, :check_conflicts, :flag, :target, :copy, :gist, :report_command, :report_counts,
295
- :recording_log, :toggle, :write_marker, :status, :clear, :doctor
331
+ private_constant :App
296
332
  end
297
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
- env["ZSH_VERSION"] || env["BASH_VERSION"]
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)
@@ -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
@@ -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
@@ -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);
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Oops
2
- VERSION = "0.6.0".freeze
2
+ VERSION = "0.7.0".freeze
3
3
  end
data/lib/oops.rb CHANGED
@@ -7,6 +7,7 @@ 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"
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.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ysb3996-blip
@@ -35,6 +35,7 @@ files:
35
35
  - lib/oops/gist.rb
36
36
  - lib/oops/marker.rb
37
37
  - lib/oops/paths.rb
38
+ - lib/oops/picker.rb
38
39
  - lib/oops/prompt_sp.rb
39
40
  - lib/oops/record.rb
40
41
  - lib/oops/recorder.rb