oops-cli 0.6.0 → 0.8.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 +15 -0
- data/CHANGELOG.md +15 -0
- data/README.ja.md +63 -11
- data/README.md +63 -11
- data/lib/oops/cli.rb +289 -228
- data/lib/oops/doctor.rb +4 -1
- data/lib/oops/picker.rb +65 -0
- data/lib/oops/record.rb +15 -1
- data/lib/oops/secrets.rb +9 -1
- data/lib/oops/session_log.rb +4 -2
- 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 +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d82a1eea58fbd7e1c5c9783eb60e3381ba90b9787cee46f2fab29073c608b33
|
|
4
|
+
data.tar.gz: 434bb7652783241d7bdbdf00b378d829215fc6361b761b2631eec0d859e0f426
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4b3dd35b39080ef704399494a8f143efdaff7da409def6defbb51a7feea511ac0089b96074f6cecfc4e288aacf7e7f7264e927f6debd349c72c337d11f7db5f
|
|
7
|
+
data.tar.gz: 36f1266ff59ee99743bfc1bc7c366762272a286490c197a83f0fe8ec2d090a4d3498663e1680e5e48751bddf9dccb489adcca3368a3073126c85ed5523cf7edc
|
data/CHANGELOG.ja.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
[English](CHANGELOG.md) | 日本語
|
|
4
4
|
|
|
5
|
+
## 0.8.0 - 2026-11-15
|
|
6
|
+
|
|
7
|
+
- 追加: `oops grep TEXT` で、コマンドか出力に `TEXT` を含む直近のコマンドをコピーできるようにしました(文字はそのまま比べ、大文字小文字と出力の色は無視)。`oops pick` の 10 件より前のコマンドも探せます。`-n N` で一致した直近 N 件、`--pick` で一致したものを並べて選べ、ほかのオプションは `oops N` と同じように使えます([#112](https://github.com/ysb3996-blip/oops/issues/112))。
|
|
8
|
+
- 修正: Sentry の組織認証トークン(`sntrys_`)を、記録されたコマンドと出力でマスクするようにしました([#15](https://github.com/ysb3996-blip/oops/issues/15))。[@jdotc1](https://github.com/jdotc1) さんによる貢献([#115](https://github.com/ysb3996-blip/oops/pull/115))。
|
|
9
|
+
- 修正: Shopify のアクセストークン(`shpat_`、`shpca_`、`shppa_`)を、記録されたコマンドと出力でマスクするようにしました([#15](https://github.com/ysb3996-blip/oops/issues/15))。[@jdotc1](https://github.com/jdotc1) さんによる貢献([#114](https://github.com/ysb3996-blip/oops/pull/114))。
|
|
10
|
+
- 修正: Hugging Face の `hf_` アクセストークンを、記録されたコマンドと出力でマスクするようにしました([#15](https://github.com/ysb3996-blip/oops/issues/15))。[@jdotc1](https://github.com/jdotc1) さんによる貢献([#101](https://github.com/ysb3996-blip/oops/pull/101))。
|
|
11
|
+
- 修正: SendGrid API キーを、記録されたコマンドと出力でマスクするようにしました([#15](https://github.com/ysb3996-blip/oops/issues/15))。[@jdotc1](https://github.com/jdotc1) さんによる貢献([#102](https://github.com/ysb3996-blip/oops/pull/102))。
|
|
12
|
+
|
|
13
|
+
## 0.7.0 - 2026-11-13
|
|
14
|
+
|
|
15
|
+
- 追加: `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))。
|
|
16
|
+
- 追加: 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))。
|
|
17
|
+
- 修正: `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` か新しいタブで反映されます。
|
|
18
|
+
- 修正: 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))。
|
|
19
|
+
|
|
5
20
|
## 0.6.0 - 2026-11-10
|
|
6
21
|
|
|
7
22
|
- 追加: `--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,21 @@
|
|
|
2
2
|
|
|
3
3
|
English | [日本語](CHANGELOG.ja.md)
|
|
4
4
|
|
|
5
|
+
## 0.8.0 - 2026-11-15
|
|
6
|
+
|
|
7
|
+
- Added: `oops grep TEXT` copies the last command whose command line or output contains `TEXT` (fixed text, case-insensitive, colors ignored), so a command older than `oops pick`'s 10 can be found. `-n N` copies the last N matches, `--pick` lists the matches to choose from, and the other options work as with `oops N` ([#112](https://github.com/ysb3996-blip/oops/issues/112)).
|
|
8
|
+
- Fixed: Sentry organization authentication tokens (`sntrys_`) are masked in captured commands and output ([#15](https://github.com/ysb3996-blip/oops/issues/15)). Contributed by [@jdotc1](https://github.com/jdotc1) in [#115](https://github.com/ysb3996-blip/oops/pull/115).
|
|
9
|
+
- Fixed: Shopify access tokens (`shpat_`, `shpca_`, `shppa_`) are masked in captured commands and output ([#15](https://github.com/ysb3996-blip/oops/issues/15)). Contributed by [@jdotc1](https://github.com/jdotc1) in [#114](https://github.com/ysb3996-blip/oops/pull/114).
|
|
10
|
+
- Fixed: Hugging Face `hf_` access 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 [#101](https://github.com/ysb3996-blip/oops/pull/101).
|
|
11
|
+
- Fixed: SendGrid API keys are masked in captured commands and output ([#15](https://github.com/ysb3996-blip/oops/issues/15)). Contributed by [@jdotc1](https://github.com/jdotc1) in [#102](https://github.com/ysb3996-blip/oops/pull/102).
|
|
12
|
+
|
|
13
|
+
## 0.7.0 - 2026-11-13
|
|
14
|
+
|
|
15
|
+
- 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)).
|
|
16
|
+
- 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)).
|
|
17
|
+
- 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.
|
|
18
|
+
- 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).
|
|
19
|
+
|
|
5
20
|
## 0.6.0 - 2026-11-10
|
|
6
21
|
|
|
7
22
|
- 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,8 @@ 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)) |
|
|
122
|
+
| `oops grep TEXT` | コマンドか出力に `TEXT` を含む直近のコマンドをコピーする。大文字小文字は区別しない([下記](#oops-grep)) |
|
|
109
123
|
| `oops init zsh` / `oops init bash` / `oops init fish` | シェルのスニペットを出力する(`eval` 用。fish は `\| source`) |
|
|
110
124
|
| `oops doctor` | 記録・フック・クリップボード・設定・ログサイズを診断する |
|
|
111
125
|
| `oops pause` / `oops resume` | 記録を止める/再開する。停止中は何もディスクに書かれない |
|
|
@@ -114,24 +128,25 @@ oops init fish | source
|
|
|
114
128
|
| `oops record -- <shell>` | 内部用: 記録用プログラムの下でシェルを起動する。スニペットが呼び出す |
|
|
115
129
|
| `oops --version`, `oops --help` | バージョンと使い方 |
|
|
116
130
|
|
|
117
|
-
`oops`、`oops N`、`oops err` のオプション:
|
|
131
|
+
`oops`、`oops N`、`oops err`、`oops pick`、`oops grep` のオプション:
|
|
118
132
|
|
|
119
133
|
| オプション | 内容 |
|
|
120
134
|
|---|---|
|
|
121
|
-
| `-n N` | 直前の N コマンドをコピーする(`err` と併用すると直近の失敗した N
|
|
135
|
+
| `-n N` | 直前の N コマンドをコピーする(`err` と併用すると直近の失敗した N コマンド、`grep` と併用すると一致した直近の N コマンド、`pick` と併用すると N 件を並べる) |
|
|
122
136
|
| `--github` | GitHub の issue / PR コメント向けの書式にする |
|
|
123
137
|
| `--time` | 各コマンドの開始時刻を `# 2026-10-31 19:30:09 +09:00` の行として付ける |
|
|
124
138
|
| `--output-only` | `$ コマンド` の行を省き、出力だけをコピーする |
|
|
125
139
|
| `-p`, `--print` | クリップボードの代わりに標準出力へ書き出す(`copied:` 行は出さない) |
|
|
126
140
|
| `--json` | コマンドを JSON で標準出力へ書き出す(スクリプトやエージェント向け) |
|
|
127
141
|
| `--gist` | [GitHub CLI](https://cli.github.com) で secret gist に上げ、その URL をコピーする([下記](#--gist)) |
|
|
142
|
+
| `--pick` | `grep` と併用すると、一致したものを番号付きで並べ、`oops pick` と同じように打った番号のものをコピーする |
|
|
128
143
|
| `--show-secrets` | 秘密情報をマスクせず、置換テーブルも適用しない |
|
|
129
144
|
|
|
130
145
|
`N` は正の整数で指定します。件数は位置引数の `N` または `-n N` のどちらかで 1 回だけ指定でき、併用や `-n` の繰り返しは使い方の誤りになります。対象のコマンドが指定件数より少なければ、見つかった分をコピーします。`-n` は上記の書式オプションと併用できます。
|
|
131
146
|
|
|
132
147
|
`oops` 自身はコピー対象になりません。直前のコマンドが `oops` だった場合は、その前のコマンドがコピーされます。
|
|
133
148
|
|
|
134
|
-
終了コード: `0` コピーした(または `--print`・`--json` で出力した、`--gist` で上げた)、`1`
|
|
149
|
+
終了コード: `0` コピーした(または `--print`・`--json` で出力した、`--gist` で上げた)、`1` コピーしなかった(記録していない、まだコマンドがない、失敗したコマンドがない、その文字を含むコマンドがない、何も選ばなかった、一時停止中、クリップボードのコマンドが失敗、`--gist` で `gh` が失敗)、`2` 使い方の誤り。
|
|
135
150
|
|
|
136
151
|
### 標準の出力
|
|
137
152
|
|
|
@@ -220,6 +235,42 @@ oops 自身は GitHub とやり取りしません。[GitHub CLI](https://cli.git
|
|
|
220
235
|
|
|
221
236
|
secret gist は一覧にも検索にも出ませんが、URL を知っていれば誰でも開けます。そのため秘密情報は必ずマスクします。`--show-secrets` を `--gist` と併用すると使い方の誤りになり、`--print`・`--json` との併用も同じです。要らなくなった gist は、gist.github.com か `gh gist delete` で消してください。クリップボードのツールが見つからないときも URL は表示し、コピーできなかったことを警告します。
|
|
222
237
|
|
|
238
|
+
### `oops pick`
|
|
239
|
+
|
|
240
|
+
`oops pick` は、このタブの直近 10 コマンドを古い順に番号付きで並べ、どれをコピーするか聞きます:
|
|
241
|
+
|
|
242
|
+
```
|
|
243
|
+
$ oops pick
|
|
244
|
+
1 $ bundle exec rake (exit 1, 84 lines, 19:30)
|
|
245
|
+
2 $ git status (exit 0, 6 lines, 19:31)
|
|
246
|
+
3 $ curl -s localhost:3000/api (exit 0, 1 line, 19:32)
|
|
247
|
+
pick> 1 3
|
|
248
|
+
copied: $ bundle exec rake (85 lines)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
番号を 1 つ、複数(`1 3`)、または範囲(`2-4`)で打つと、実行した順に、`oops 3` と同じ整形とマスクでコピーします。何も打たずに Enter を押すと何もコピーしません。一覧のコマンドもマスク済みです。`-n 20` で 20 件並べます。整形のオプションもそのまま使えます(`oops pick --github`、`oops pick -p | less` など。一覧と `pick>` は標準エラーに出るので、標準出力には本文だけが出ます)。
|
|
252
|
+
|
|
253
|
+
### `oops grep`
|
|
254
|
+
|
|
255
|
+
`oops pick` でさかのぼれるのは 10 コマンドまでです。もっと前のものは、コマンドか出力に含まれる言葉で探せます:
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
$ oops grep nomethoderror
|
|
259
|
+
copied: $ bundle exec rspec (42 lines)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
文字はそのまま比べ(`.` や `*` に特別な意味はありません)、大文字小文字は区別しません。出力の色も無視します。`grep` のあとの言葉はスペースでつなげるので、`oops grep no such file` のように引用符は要りません。`-` で始まる文字を探すときは前に `--` を置きます。`-n 3` で一致した直近の 3 コマンドを古い順にコピーし、`--pick` で一致したもの(最大 10 件、`-n N` で N 件)を並べて選べます:
|
|
263
|
+
|
|
264
|
+
```
|
|
265
|
+
$ oops grep docker --pick
|
|
266
|
+
1 $ docker compose up -d (exit 0, 3 lines, 18:02)
|
|
267
|
+
2 $ docker compose logs web (exit 0, 120 lines, 18:40)
|
|
268
|
+
pick> 2
|
|
269
|
+
copied: $ docker compose logs web (120 lines)
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
探すのはこのタブの記録だけです。比べるのはマスク前の文字ですが、コピーや一覧の中身はいつもどおりマスクされます。
|
|
273
|
+
|
|
223
274
|
### `oops status`
|
|
224
275
|
|
|
225
276
|
`oops status` は `recording`・`paused`・`off`(このシェルが記録されていない、またはログが削除された)のどれかを出力し、記録中のときだけ終了コード `0` を返します。エラーは出さないので、プロンプトやスクリプトから呼べます(例: [starship のカスタムモジュール](https://starship.rs/config/#custom-commands))。呼ぶたびに Ruby が起動するため 0.1〜0.2 秒ほどかかります。`off` のときの詳しい理由は `oops doctor` で分かります。
|
|
@@ -395,11 +446,11 @@ bundle exec exe/oops doctor
|
|
|
395
446
|
|
|
396
447
|
```sh
|
|
397
448
|
gem build oops-cli.gemspec
|
|
398
|
-
gem install ./oops-cli-0.
|
|
449
|
+
gem install ./oops-cli-0.8.0.gem # ファイル名は lib/oops/version.rb に合わせる
|
|
399
450
|
rbenv rehash # rbenv を使う場合のみ
|
|
400
451
|
```
|
|
401
452
|
|
|
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.
|
|
453
|
+
- 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.8.0.gem`)。
|
|
403
454
|
- 変更のたびに入れ直してください。インストールされた gem はコピーで、チェックアウトへのリンクではありません。
|
|
404
455
|
- 削除するには `gem uninstall oops-cli` です。
|
|
405
456
|
- `eval "$(oops init zsh)"` は、プロンプトで打つだけでなく rc ファイルに書いてください。記録されるシェルは rc ファイルを読み直すため、行がないとフックが入りません(`oops doctor` に `hooks: missing` と出ます)。
|
|
@@ -417,7 +468,7 @@ rbenv rehash # rbenv を使う場合のみ
|
|
|
417
468
|
|
|
418
469
|
## コントリビュート
|
|
419
470
|
|
|
420
|
-
バグ報告、アイデア、プルリクエストを歓迎します。[CONTRIBUTING.ja.md](CONTRIBUTING.ja.md) を読んでください。`good first issue` のラベルが付いた issue
|
|
471
|
+
バグ報告、アイデア、プルリクエストを歓迎します。[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
472
|
|
|
422
473
|
## 貢献してくれた人たち
|
|
423
474
|
|
|
@@ -429,11 +480,12 @@ rbenv rehash # rbenv を使う場合のみ
|
|
|
429
480
|
<table>
|
|
430
481
|
<tbody>
|
|
431
482
|
<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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
483
|
+
<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>
|
|
484
|
+
<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>
|
|
485
|
+
<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>
|
|
486
|
+
<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>
|
|
487
|
+
<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>
|
|
488
|
+
<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
489
|
</tr>
|
|
438
490
|
</tbody>
|
|
439
491
|
</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,8 @@ 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)) |
|
|
122
|
+
| `oops grep TEXT` | Copy the last command whose command line or output contains `TEXT`, ignoring case ([below](#oops-grep)) |
|
|
109
123
|
| `oops init zsh` / `oops init bash` / `oops init fish` | Print the shell snippet (for `eval`, or `\| source` in fish) |
|
|
110
124
|
| `oops doctor` | Diagnose recording, hooks, clipboard, config and log size |
|
|
111
125
|
| `oops pause` / `oops resume` | Stop and restart recording. While paused, nothing is written to disk |
|
|
@@ -114,24 +128,25 @@ To turn oops off for one shell, start it with `OOPS_DISABLE=1` (for example `OOP
|
|
|
114
128
|
| `oops record -- <shell>` | Internal: runs a shell under the recorder. The snippet calls this |
|
|
115
129
|
| `oops --version`, `oops --help` | Version and usage |
|
|
116
130
|
|
|
117
|
-
Options for `oops`, `oops N` and `oops
|
|
131
|
+
Options for `oops`, `oops N`, `oops err`, `oops pick` and `oops grep`:
|
|
118
132
|
|
|
119
133
|
| Option | What it does |
|
|
120
134
|
|---|---|
|
|
121
|
-
| `-n N` | Copy the last N commands (with `err`, the last N failed commands) |
|
|
135
|
+
| `-n N` | Copy the last N commands (with `err`, the last N failed commands; with `grep`, the last N matches; with `pick`, list N) |
|
|
122
136
|
| `--github` | Format for a GitHub issue or PR comment |
|
|
123
137
|
| `--time` | Add the time each command started as a `# 2026-10-31 19:30:09 +09:00` line |
|
|
124
138
|
| `--output-only` | Leave out the `$ command` line and copy only the output |
|
|
125
139
|
| `-p`, `--print` | Write the text to stdout instead of the clipboard (no `copied:` line) |
|
|
126
140
|
| `--json` | Write the commands as JSON to stdout, for scripts and agents |
|
|
127
141
|
| `--gist` | Upload the text as a secret gist with the [GitHub CLI](https://cli.github.com) and copy its URL ([below](#--gist)) |
|
|
142
|
+
| `--pick` | With `grep`, list the matches with numbers and copy the ones you type, as `oops pick` does |
|
|
128
143
|
| `--show-secrets` | Do not mask secrets and do not apply the replace table |
|
|
129
144
|
|
|
130
145
|
`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.
|
|
131
146
|
|
|
132
147
|
`oops` never copies itself: if the previous command was `oops`, you get the command before it.
|
|
133
148
|
|
|
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.
|
|
149
|
+
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, no command containing the text, nothing picked, paused, the clipboard command failed, or `gh` failed with `--gist`), `2` usage error.
|
|
135
150
|
|
|
136
151
|
### Default output
|
|
137
152
|
|
|
@@ -220,6 +235,42 @@ oops does not talk to GitHub itself: it runs `gh gist create` from the [GitHub C
|
|
|
220
235
|
|
|
221
236
|
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
237
|
|
|
238
|
+
### `oops pick`
|
|
239
|
+
|
|
240
|
+
`oops pick` lists the last 10 commands of this tab, oldest first, and asks which to copy:
|
|
241
|
+
|
|
242
|
+
```
|
|
243
|
+
$ oops pick
|
|
244
|
+
1 $ bundle exec rake (exit 1, 84 lines, 19:30)
|
|
245
|
+
2 $ git status (exit 0, 6 lines, 19:31)
|
|
246
|
+
3 $ curl -s localhost:3000/api (exit 0, 1 line, 19:32)
|
|
247
|
+
pick> 1 3
|
|
248
|
+
copied: $ bundle exec rake (85 lines)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
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).
|
|
252
|
+
|
|
253
|
+
### `oops grep`
|
|
254
|
+
|
|
255
|
+
`oops pick` only goes back 10 commands. To find an older one, search for a word from the command or from its output:
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
$ oops grep nomethoderror
|
|
259
|
+
copied: $ bundle exec rspec (42 lines)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
The text is matched as is (`.` and `*` are not special) and case does not matter; colors in the output are ignored. The words after `grep` are joined with spaces, so `oops grep no such file` needs no quotes; put `--` before text that starts with `-`. `-n 3` copies the last 3 matches, oldest first, and `--pick` lists up to 10 matches (or `-n N`) to choose from:
|
|
263
|
+
|
|
264
|
+
```
|
|
265
|
+
$ oops grep docker --pick
|
|
266
|
+
1 $ docker compose up -d (exit 0, 3 lines, 18:02)
|
|
267
|
+
2 $ docker compose logs web (exit 0, 120 lines, 18:40)
|
|
268
|
+
pick> 2
|
|
269
|
+
copied: $ docker compose logs web (120 lines)
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
The search covers this tab only. Commands are matched before masking, but what is copied or listed is masked as usual.
|
|
273
|
+
|
|
223
274
|
### `oops status`
|
|
224
275
|
|
|
225
276
|
`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 +446,11 @@ To try it as your shell does, build and install the gem into the Ruby you are us
|
|
|
395
446
|
|
|
396
447
|
```sh
|
|
397
448
|
gem build oops-cli.gemspec
|
|
398
|
-
gem install ./oops-cli-0.
|
|
449
|
+
gem install ./oops-cli-0.8.0.gem # the file name follows lib/oops/version.rb
|
|
399
450
|
rbenv rehash # only with rbenv
|
|
400
451
|
```
|
|
401
452
|
|
|
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.
|
|
453
|
+
- 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.8.0.gem`.
|
|
403
454
|
- Reinstall after every change. The installed gem is a copy, not a link to your checkout.
|
|
404
455
|
- To remove it: `gem uninstall oops-cli`.
|
|
405
456
|
- 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 +468,7 @@ Manual checklist before a release:
|
|
|
417
468
|
|
|
418
469
|
## Contributing
|
|
419
470
|
|
|
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).
|
|
471
|
+
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
472
|
|
|
422
473
|
## Contributors
|
|
423
474
|
|
|
@@ -429,11 +480,12 @@ Thanks to everyone who has helped ([emoji key](https://allcontributors.org/docs/
|
|
|
429
480
|
<table>
|
|
430
481
|
<tbody>
|
|
431
482
|
<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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
483
|
+
<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>
|
|
484
|
+
<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>
|
|
485
|
+
<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>
|
|
486
|
+
<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>
|
|
487
|
+
<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>
|
|
488
|
+
<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
489
|
</tr>
|
|
438
490
|
</tbody>
|
|
439
491
|
</table>
|
data/lib/oops/cli.rb
CHANGED
|
@@ -11,287 +11,348 @@ 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, :containing)
|
|
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
|
+
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
|
|
48
|
+
options = { github: false, show_secrets: false, time: false, output_only: false, print: false,
|
|
49
|
+
json: false, gist: false }
|
|
50
|
+
count = nil
|
|
51
|
+
pick = false
|
|
52
|
+
parser = OptionParser.new do |o|
|
|
53
|
+
o.banner = "Usage: oops [N | err | pick | grep TEXT] [-n N] [options]\n " \
|
|
54
|
+
"oops init <shell> | pause | resume | status | clear [--all] | doctor"
|
|
55
|
+
o.on("-n N", "Copy the last N commands (with err, last N failures; " \
|
|
56
|
+
"with grep, last N matches; with pick, list N)") do |v|
|
|
57
|
+
raise UsageError, COUNT_REPEATED if count
|
|
58
|
+
|
|
59
|
+
count = positive(v, "-n")
|
|
60
|
+
end
|
|
61
|
+
o.on("--github", "Format for a GitHub issue or PR comment") { options[:github] = true }
|
|
62
|
+
o.on("--time", "Add the time each command started") { options[:time] = true }
|
|
63
|
+
o.on("--output-only", "Leave out the command line, keep the output") { options[:output_only] = true }
|
|
64
|
+
o.on("--show-secrets", "Do not mask secrets or apply the replace table") { options[:show_secrets] = true }
|
|
65
|
+
o.on("-p", "--print", "Write the text to stdout instead of the clipboard") { options[:print] = true }
|
|
66
|
+
o.on("--json", "Write the commands as JSON to stdout") { options[:json] = true }
|
|
67
|
+
o.on("--gist", "Upload as a secret gist (needs gh) and copy its URL") { options[:gist] = true }
|
|
68
|
+
o.on("--pick", "With grep, list the matches and copy the ones you choose") { pick = true }
|
|
69
|
+
o.on("-v", "--version", "Print version and exit") do
|
|
70
|
+
stdout.puts "oops #{VERSION}"
|
|
71
|
+
return 0
|
|
72
|
+
end
|
|
73
|
+
o.on("-h", "--help", "Print this help and exit") do
|
|
74
|
+
stdout.puts o
|
|
75
|
+
return 0
|
|
76
|
+
end
|
|
53
77
|
end
|
|
78
|
+
copy_target = target(parser.parse(argv), count: count, pick: pick)
|
|
79
|
+
check_conflicts(options)
|
|
80
|
+
copy(copy_target, options)
|
|
81
|
+
rescue OptionParser::ParseError, UsageError => e
|
|
82
|
+
stderr.puts "oops: #{e.message}"
|
|
83
|
+
2
|
|
84
|
+
rescue Failure => e
|
|
85
|
+
stderr.puts "oops: #{e.message}"
|
|
86
|
+
1
|
|
54
87
|
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
88
|
|
|
66
|
-
|
|
67
|
-
raise UsageError, "#{name} must be a positive integer" unless value.match?(POSITIVE_INTEGER) && value.to_i >= 1
|
|
89
|
+
private
|
|
68
90
|
|
|
69
|
-
|
|
70
|
-
end
|
|
91
|
+
attr_reader :env, :stdin, :stdout, :stderr
|
|
71
92
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
private_constant :CONFLICTS
|
|
93
|
+
def positive(value, name)
|
|
94
|
+
raise UsageError, "#{name} must be a positive integer" unless value.match?(POSITIVE_INTEGER) && value.to_i >= 1
|
|
95
|
+
|
|
96
|
+
value.to_i
|
|
97
|
+
end
|
|
78
98
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
99
|
+
def check_conflicts(options)
|
|
100
|
+
CONFLICTS.each do |option, others|
|
|
101
|
+
next unless options[option]
|
|
82
102
|
|
|
83
|
-
|
|
84
|
-
|
|
103
|
+
conflict = others.find { |key| options[key] }
|
|
104
|
+
raise UsageError, "--#{option} cannot be combined with #{flag(conflict)}" if conflict
|
|
105
|
+
end
|
|
85
106
|
end
|
|
86
|
-
end
|
|
87
107
|
|
|
88
|
-
|
|
108
|
+
def flag(key) = "--#{key.to_s.tr('_', '-')}"
|
|
89
109
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
110
|
+
# Count comes from either a positional N or -n N. "err" filters the
|
|
111
|
+
# selection to failed commands; without a count, one command is copied.
|
|
112
|
+
# "pick" lists the last count commands (Picker::COUNT by default) and
|
|
113
|
+
# copies the ones the user chooses. "grep TEXT" counts only commands
|
|
114
|
+
# whose command line or output contain TEXT; the words after grep are
|
|
115
|
+
# joined, so the text needs no quotes.
|
|
116
|
+
def target(args, count:, pick:)
|
|
117
|
+
return grep_target(args.drop(1), count: count, pick: pick) if args.first == "grep"
|
|
118
|
+
raise UsageError, "--pick works only with grep; use oops pick for the last commands" if pick
|
|
119
|
+
raise UsageError, "unexpected argument: #{args[1]}" if args.size > 1
|
|
94
120
|
|
|
95
|
-
|
|
96
|
-
|
|
121
|
+
arg = args.first
|
|
122
|
+
return copy_target(count: count || Picker::COUNT, pick: true) if arg == "pick"
|
|
123
|
+
return copy_target(count: count || 1, failed_only: arg == "err") if arg.nil? || arg == "err"
|
|
97
124
|
|
|
98
|
-
|
|
99
|
-
|
|
125
|
+
raise UsageError, "unknown command: #{arg}" unless arg.match?(/\A[+-]?\d/)
|
|
126
|
+
raise UsageError, COUNT_REPEATED if count
|
|
100
127
|
|
|
101
|
-
|
|
102
|
-
|
|
128
|
+
copy_target(count: positive(arg, "N"))
|
|
129
|
+
end
|
|
103
130
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
131
|
+
def grep_target(words, count:, pick:)
|
|
132
|
+
text = words.join(" ")
|
|
133
|
+
raise UsageError, "oops grep needs the text to search for" if text.empty?
|
|
107
134
|
|
|
108
|
-
|
|
109
|
-
|
|
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?
|
|
135
|
+
copy_target(count: count || (pick ? Picker::COUNT : 1), pick: pick, containing: text)
|
|
136
|
+
end
|
|
112
137
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if options[:json]
|
|
116
|
-
stdout.write formatter.json(records)
|
|
117
|
-
return 0
|
|
138
|
+
def copy_target(count:, failed_only: false, pick: false, containing: nil)
|
|
139
|
+
CopyTarget.new(count: count, failed_only: failed_only, pick: pick, containing: containing)
|
|
118
140
|
end
|
|
119
141
|
|
|
120
|
-
|
|
121
|
-
|
|
142
|
+
def copy(target, options)
|
|
143
|
+
log = recording_log
|
|
144
|
+
raise Failure, "recording is paused. Run oops resume first." if log.paused?
|
|
122
145
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
146
|
+
config = Config.load(env: env)
|
|
147
|
+
config.warnings.each { |w| stderr.puts "oops: warning: #{w}" }
|
|
148
|
+
records = log.last(target.count, failed_only: target.failed_only, containing: target.containing)
|
|
149
|
+
raise Failure, not_found(target) if records.empty?
|
|
127
150
|
|
|
128
|
-
|
|
129
|
-
|
|
151
|
+
home = env["HOME"].to_s.empty? ? Dir.home : env["HOME"]
|
|
152
|
+
records = pick(records, config: config, home: home, show_secrets: options[:show_secrets]) if target.pick
|
|
153
|
+
formatter = Formatter.new(config: config, home: home, **options.except(:print, :json, :gist))
|
|
154
|
+
if options[:json]
|
|
155
|
+
stdout.write formatter.json(records)
|
|
156
|
+
return 0
|
|
157
|
+
end
|
|
130
158
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
159
|
+
result = formatter.format(records)
|
|
160
|
+
return gist(result, config: config) if options[:gist]
|
|
161
|
+
|
|
162
|
+
if options[:print]
|
|
163
|
+
stdout.write result.text
|
|
164
|
+
return 0
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
backend = Clipboard.detect(config.clipboard, env: env)
|
|
168
|
+
raise Failure, NO_CLIPBOARD if backend.nil?
|
|
169
|
+
|
|
170
|
+
begin
|
|
171
|
+
backend.copy(result.text)
|
|
172
|
+
rescue Clipboard::Error => e
|
|
173
|
+
raise Failure, e.message
|
|
174
|
+
end
|
|
175
|
+
stdout.puts "copied: $ #{report_command(result.command_line)} (#{report_counts(result)})"
|
|
176
|
+
0
|
|
135
177
|
end
|
|
136
|
-
stdout.puts "copied: $ #{report_command(result.command_line)} (#{report_counts(result)})"
|
|
137
|
-
0
|
|
138
|
-
end
|
|
139
178
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
rescue Gist::Error => e
|
|
146
|
-
raise Failure, e.message
|
|
179
|
+
def not_found(target)
|
|
180
|
+
if target.containing then %(no command containing "#{target.containing}" found.)
|
|
181
|
+
elsif target.failed_only then "no failed command found."
|
|
182
|
+
else "no command found yet."
|
|
183
|
+
end
|
|
147
184
|
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
185
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
186
|
+
# `oops pick`: the list and the prompt go to stderr, so `oops pick -p`
|
|
187
|
+
# and `--json` keep stdout for the copied text. The answer is read from
|
|
188
|
+
# stdin, which also lets a script pipe the numbers in.
|
|
189
|
+
def pick(records, config:, home:, show_secrets:)
|
|
190
|
+
lister = Formatter.new(config: config, home: home, show_secrets: show_secrets)
|
|
191
|
+
stderr.puts Picker.menu(records, lister)
|
|
192
|
+
stderr.print "pick> "
|
|
193
|
+
stderr.flush
|
|
194
|
+
answer = stdin.gets
|
|
195
|
+
# A terminal echoes the answer and its newline; piped input does not.
|
|
196
|
+
stderr.puts unless stdin.tty?
|
|
197
|
+
records.values_at(*Picker.parse(answer, records.size).map { |n| n - 1 })
|
|
198
|
+
rescue Picker::Invalid => e
|
|
199
|
+
raise Failure, e.message
|
|
156
200
|
end
|
|
157
|
-
0
|
|
158
|
-
end
|
|
159
201
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
202
|
+
# The gist is made before the clipboard is tried, so a missing or failing
|
|
203
|
+
# clipboard only costs a warning: the URL is on stdout either way.
|
|
204
|
+
def gist(result, config:)
|
|
205
|
+
url = begin
|
|
206
|
+
Gist.create(result.text, description: "oops: $ #{report_command(result.command_line)}", env: env)
|
|
207
|
+
rescue Gist::Error => e
|
|
208
|
+
raise Failure, e.message
|
|
209
|
+
end
|
|
210
|
+
stdout.puts "gist: #{url} (#{report_counts(result)})"
|
|
211
|
+
begin
|
|
212
|
+
backend = Clipboard.detect(config.clipboard, env: env)
|
|
213
|
+
raise Clipboard::Error, NO_CLIPBOARD if backend.nil?
|
|
164
214
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
215
|
+
backend.copy(url)
|
|
216
|
+
rescue Clipboard::Error => e
|
|
217
|
+
stderr.puts "oops: warning: the URL was not copied: #{e.message}"
|
|
218
|
+
end
|
|
219
|
+
0
|
|
220
|
+
end
|
|
169
221
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
|
222
|
+
def report_command(command_line)
|
|
223
|
+
first, rest = command_line.to_s.split("\n", 2)
|
|
224
|
+
rest ? "#{first} ..." : first.to_s
|
|
225
|
+
end
|
|
185
226
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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)
|
|
227
|
+
def report_counts(result)
|
|
228
|
+
counts = "#{result.lines} lines"
|
|
229
|
+
result.masked_count.positive? ? "#{counts}, #{result.masked_count} secrets masked" : counts
|
|
200
230
|
end
|
|
201
|
-
0
|
|
202
|
-
end
|
|
203
231
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
232
|
+
# The session log of the recorder this shell runs under. Raises Failure
|
|
233
|
+
# when there is none.
|
|
234
|
+
def recording_log
|
|
235
|
+
path = env["OOPS_SESSION"].to_s
|
|
236
|
+
return SessionLog.new(path) if !path.empty? && File.file?(path)
|
|
237
|
+
|
|
238
|
+
line, rc = case env["SHELL"].to_s
|
|
239
|
+
when /bash\z/ then [%(eval "$(oops init bash)"), "~/.bashrc"]
|
|
240
|
+
when /fish\z/ then ["oops init fish | source", "~/.config/fish/config.fish"]
|
|
241
|
+
else [%(eval "$(oops init zsh)"), "~/.zshrc"]
|
|
242
|
+
end
|
|
243
|
+
raise Failure, "not recording in this shell. Add #{line} " \
|
|
244
|
+
"to #{rc} (after whatever puts oops's Ruby on PATH, as early as possible) " \
|
|
245
|
+
"and open a new tab."
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# `oops pause` / `oops resume`: the marker goes through the pty to the
|
|
249
|
+
# recorder; the flag file tells `oops` (and `doctor`) the state. The
|
|
250
|
+
# recorder only obeys a marker that agrees with the flag file, so the
|
|
251
|
+
# file changes first.
|
|
252
|
+
def toggle(name, args)
|
|
253
|
+
raise UsageError, "usage: oops #{name}" unless args.empty?
|
|
254
|
+
|
|
255
|
+
log = recording_log
|
|
256
|
+
if name == "pause"
|
|
257
|
+
log.pause!
|
|
258
|
+
write_marker(Marker.pause)
|
|
259
|
+
else
|
|
260
|
+
log.resume!
|
|
261
|
+
write_marker(Marker.resume)
|
|
215
262
|
end
|
|
263
|
+
0
|
|
216
264
|
end
|
|
217
|
-
stdout.write marker
|
|
218
|
-
stdout.flush
|
|
219
|
-
end
|
|
220
265
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
266
|
+
# Like the shell hooks, write straight to the recorded terminal: with
|
|
267
|
+
# stdout redirected (`oops pause >/dev/null`) the recorder would never see
|
|
268
|
+
# the marker although the flag file already says "paused". Without a
|
|
269
|
+
# terminal that can be opened, stdout is used.
|
|
270
|
+
def write_marker(marker)
|
|
271
|
+
tty = env["OOPS_TTY"].to_s
|
|
272
|
+
unless tty.empty?
|
|
273
|
+
begin
|
|
274
|
+
return File.open(tty, File::WRONLY | File::NOCTTY) { |io| io.write(marker) }
|
|
275
|
+
rescue SystemCallError, IOError
|
|
276
|
+
nil
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
stdout.write marker
|
|
280
|
+
stdout.flush
|
|
228
281
|
end
|
|
229
282
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
283
|
+
# `oops status`: one word on stdout. "recording" exits 0; "paused" and
|
|
284
|
+
# "off" (this shell is not recorded, or its log is gone) exit 1 without a
|
|
285
|
+
# message, so a prompt can call it.
|
|
286
|
+
def status(args)
|
|
287
|
+
unless args.empty?
|
|
288
|
+
stderr.puts "oops: usage: oops status"
|
|
289
|
+
return 2
|
|
290
|
+
end
|
|
238
291
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
292
|
+
path = env["OOPS_SESSION"].to_s
|
|
293
|
+
word = if path.empty? || !File.file?(path) then "off"
|
|
294
|
+
elsif SessionLog.new(path).paused? then "paused"
|
|
295
|
+
else "recording"
|
|
296
|
+
end
|
|
297
|
+
stdout.puts word
|
|
298
|
+
word == "recording" ? 0 : 1
|
|
299
|
+
end
|
|
243
300
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return 0 unless log
|
|
301
|
+
# `oops clear [--all]`: deletes the logs of closed tabs; with --all, also
|
|
302
|
+
# empties this tab's log. Logs of other open tabs are never touched.
|
|
303
|
+
def clear(args)
|
|
304
|
+
raise UsageError, "usage: oops clear [--all]" unless args.empty? || args == ["--all"]
|
|
249
305
|
|
|
250
|
-
log
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
0
|
|
256
|
-
end
|
|
306
|
+
log = recording_log if args == ["--all"]
|
|
307
|
+
begin
|
|
308
|
+
removed = SessionLog.clear!(Paths.sessions_dir(env: env))
|
|
309
|
+
stdout.puts "removed #{removed} #{removed == 1 ? 'log' : 'logs'} of closed tabs"
|
|
310
|
+
return 0 unless log
|
|
257
311
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
312
|
+
log.empty!
|
|
313
|
+
rescue SystemCallError => e
|
|
314
|
+
raise Failure, "could not delete the logs: #{e.message}"
|
|
315
|
+
end
|
|
316
|
+
stdout.puts "emptied this tab's log"
|
|
317
|
+
0
|
|
318
|
+
end
|
|
261
319
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
0
|
|
266
|
-
rescue StandardError => e
|
|
267
|
-
raise if e.is_a?(UsageError)
|
|
320
|
+
# `oops doctor`: diagnostics on stdout; always exits 0.
|
|
321
|
+
def doctor(args)
|
|
322
|
+
raise UsageError, "usage: oops doctor" unless args.empty?
|
|
268
323
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
324
|
+
config = Config.load(env: env)
|
|
325
|
+
tty = Tty.name(stdin)
|
|
326
|
+
stdout.write Doctor.report(env: env, config: config, sessions_dir: Paths.sessions_dir(env: env), tty: tty)
|
|
327
|
+
0
|
|
328
|
+
rescue StandardError => e
|
|
329
|
+
raise if e.is_a?(UsageError)
|
|
272
330
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
Recorder.new(args, env: env, stdin: stdin, stdout: stdout, stderr: stderr).run
|
|
277
|
-
end
|
|
331
|
+
stdout.puts "doctor: #{e.message}"
|
|
332
|
+
0
|
|
333
|
+
end
|
|
278
334
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
stderr.puts "oops: usage: oops init <shell> (supported: #{supported})"
|
|
284
|
-
return 2
|
|
335
|
+
# `oops record [--] <shell> [args...]`
|
|
336
|
+
def record(args)
|
|
337
|
+
args = args.drop(1) if args.first == "--"
|
|
338
|
+
Recorder.new(args, env: env, stdin: stdin, stdout: stdout, stderr: stderr).run
|
|
285
339
|
end
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
340
|
+
|
|
341
|
+
# `oops init zsh|bash|fish`: prints the snippet for `eval "$(oops init zsh)"`.
|
|
342
|
+
def init(args)
|
|
343
|
+
supported = ShellInit::SHELLS.join(", ")
|
|
344
|
+
if args.size != 1
|
|
345
|
+
stderr.puts "oops: usage: oops init <shell> (supported: #{supported})"
|
|
346
|
+
return 2
|
|
347
|
+
end
|
|
348
|
+
unless ShellInit::SHELLS.include?(args.first)
|
|
349
|
+
stderr.puts "oops: unsupported shell: #{args.first} (supported: #{supported})"
|
|
350
|
+
return 2
|
|
351
|
+
end
|
|
352
|
+
stdout.write ShellInit.snippet(args.first, bin: File.expand_path($PROGRAM_NAME))
|
|
353
|
+
0
|
|
289
354
|
end
|
|
290
|
-
stdout.write ShellInit.snippet(args.first, bin: File.expand_path($PROGRAM_NAME))
|
|
291
|
-
0
|
|
292
355
|
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
|
|
356
|
+
private_constant :App
|
|
296
357
|
end
|
|
297
358
|
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/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/record.rb
CHANGED
|
@@ -17,7 +17,21 @@ module Oops
|
|
|
17
17
|
|
|
18
18
|
value.to_s.dup.force_encoding(Encoding::UTF_8).scrub
|
|
19
19
|
end
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
# Output without escape sequences; the strip is skipped when there is none.
|
|
22
|
+
def plain_output
|
|
23
|
+
raw = output.to_s
|
|
24
|
+
raw.include?("\e") ? Ansi.strip(raw.dup) : raw
|
|
25
|
+
end
|
|
26
|
+
private :utf8_clean, :plain_output
|
|
27
|
+
|
|
28
|
+
# Whether the command line or the output contains text, ignoring case.
|
|
29
|
+
# Colors are removed from the output first, so a word colored halfway
|
|
30
|
+
# through still matches.
|
|
31
|
+
def contains?(text)
|
|
32
|
+
needle = text.downcase(:fold)
|
|
33
|
+
[cmd, plain_output].any? { |s| utf8_clean(s).to_s.downcase(:fold).include?(needle) }
|
|
34
|
+
end
|
|
21
35
|
|
|
22
36
|
def oops_self?
|
|
23
37
|
cmd.to_s.match?(%r{\A\s*(\S*/)?oops(\s|\z)})
|
data/lib/oops/secrets.rb
CHANGED
|
@@ -17,7 +17,15 @@ 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
|
-
|
|
20
|
+
/(?<![A-Za-z0-9_])hf_[A-Za-z0-9]{16,}(?![A-Za-z0-9_])/, # Hugging Face access tokens
|
|
21
|
+
/(?<![A-Za-z0-9_])(?:dop|doo|dor)_v1_[0-9a-f]{64}(?![A-Za-z0-9_])/, # DigitalOcean API tokens
|
|
22
|
+
/(?<![A-Za-z0-9_])(?:shpat|shpca|shppa)_[A-Za-z0-9]{32,}(?![A-Za-z0-9_])/, # Shopify access tokens
|
|
23
|
+
%r{
|
|
24
|
+
(?<![A-Za-z0-9_])sntrys_eyJ[A-Za-z0-9+/]{16,800}={0,2}_
|
|
25
|
+
[A-Za-z0-9+/]{43}(?![A-Za-z0-9+/=_])
|
|
26
|
+
}x, # Sentry org auth tokens
|
|
27
|
+
/\bAIza[0-9A-Za-z_-]{35}/, # Google API keys
|
|
28
|
+
/(?<![A-Za-z0-9_-])SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}(?![A-Za-z0-9_-])/, # SendGrid API keys
|
|
21
29
|
/\bnpm_[A-Za-z0-9]{36}/, # npm tokens
|
|
22
30
|
%r{hooks\.slack\.com/services/(?<secret>[A-Za-z0-9/]+)}, # Slack webhook URLs
|
|
23
31
|
/\beyJ[\w-]+\.[\w-]+\.[\w-]+/, # JWT
|
data/lib/oops/session_log.rb
CHANGED
|
@@ -156,12 +156,14 @@ module Oops
|
|
|
156
156
|
end
|
|
157
157
|
|
|
158
158
|
# Newest count finished, non-oops records, oldest first. With failed_only,
|
|
159
|
-
# only records with a non-zero integer exit status count toward the limit
|
|
160
|
-
|
|
159
|
+
# only records with a non-zero integer exit status count toward the limit;
|
|
160
|
+
# with containing, only records whose command or output contain that text.
|
|
161
|
+
def last(count, skip_oops: true, failed_only: false, containing: nil)
|
|
161
162
|
found = []
|
|
162
163
|
each_backward do |r|
|
|
163
164
|
next if r.exit.nil? || (skip_oops && r.oops_self?)
|
|
164
165
|
next if failed_only && (!r.exit.is_a?(Integer) || r.exit.zero?)
|
|
166
|
+
next if containing && !r.contains?(containing)
|
|
165
167
|
|
|
166
168
|
found << r
|
|
167
169
|
:stop if found.size >= count
|
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,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.
|
|
4
|
+
version: 0.8.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
|