oops-cli 0.7.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 +8 -0
- data/CHANGELOG.md +8 -0
- data/README.ja.md +28 -5
- data/README.md +28 -5
- data/lib/oops/cli.rb +36 -11
- data/lib/oops/record.rb +15 -1
- data/lib/oops/secrets.rb +8 -1
- data/lib/oops/session_log.rb +4 -2
- data/lib/oops/version.rb +1 -1
- metadata +1 -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,14 @@
|
|
|
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
|
+
|
|
5
13
|
## 0.7.0 - 2026-11-13
|
|
6
14
|
|
|
7
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))。
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
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
|
+
|
|
5
13
|
## 0.7.0 - 2026-11-13
|
|
6
14
|
|
|
7
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)).
|
data/README.ja.md
CHANGED
|
@@ -119,6 +119,7 @@ oops init fish | source
|
|
|
119
119
|
| `oops err` | 終了コードが 0 以外だった直近のコマンドをコピーする(成功したコマンドは飛ばす) |
|
|
120
120
|
| `oops err -n 2` | 直近の失敗した 2 コマンドを古い順にコピーする(成功したコマンドは飛ばす) |
|
|
121
121
|
| `oops pick` | 直近の 10 コマンドを番号付きで並べ、打った番号のものをコピーする([下記](#oops-pick)) |
|
|
122
|
+
| `oops grep TEXT` | コマンドか出力に `TEXT` を含む直近のコマンドをコピーする。大文字小文字は区別しない([下記](#oops-grep)) |
|
|
122
123
|
| `oops init zsh` / `oops init bash` / `oops init fish` | シェルのスニペットを出力する(`eval` 用。fish は `\| source`) |
|
|
123
124
|
| `oops doctor` | 記録・フック・クリップボード・設定・ログサイズを診断する |
|
|
124
125
|
| `oops pause` / `oops resume` | 記録を止める/再開する。停止中は何もディスクに書かれない |
|
|
@@ -127,24 +128,25 @@ oops init fish | source
|
|
|
127
128
|
| `oops record -- <shell>` | 内部用: 記録用プログラムの下でシェルを起動する。スニペットが呼び出す |
|
|
128
129
|
| `oops --version`, `oops --help` | バージョンと使い方 |
|
|
129
130
|
|
|
130
|
-
`oops`、`oops N`、`oops err`、`oops pick` のオプション:
|
|
131
|
+
`oops`、`oops N`、`oops err`、`oops pick`、`oops grep` のオプション:
|
|
131
132
|
|
|
132
133
|
| オプション | 内容 |
|
|
133
134
|
|---|---|
|
|
134
|
-
| `-n N` | 直前の N コマンドをコピーする(`err` と併用すると直近の失敗した N コマンド、`pick` と併用すると N 件を並べる) |
|
|
135
|
+
| `-n N` | 直前の N コマンドをコピーする(`err` と併用すると直近の失敗した N コマンド、`grep` と併用すると一致した直近の N コマンド、`pick` と併用すると N 件を並べる) |
|
|
135
136
|
| `--github` | GitHub の issue / PR コメント向けの書式にする |
|
|
136
137
|
| `--time` | 各コマンドの開始時刻を `# 2026-10-31 19:30:09 +09:00` の行として付ける |
|
|
137
138
|
| `--output-only` | `$ コマンド` の行を省き、出力だけをコピーする |
|
|
138
139
|
| `-p`, `--print` | クリップボードの代わりに標準出力へ書き出す(`copied:` 行は出さない) |
|
|
139
140
|
| `--json` | コマンドを JSON で標準出力へ書き出す(スクリプトやエージェント向け) |
|
|
140
141
|
| `--gist` | [GitHub CLI](https://cli.github.com) で secret gist に上げ、その URL をコピーする([下記](#--gist)) |
|
|
142
|
+
| `--pick` | `grep` と併用すると、一致したものを番号付きで並べ、`oops pick` と同じように打った番号のものをコピーする |
|
|
141
143
|
| `--show-secrets` | 秘密情報をマスクせず、置換テーブルも適用しない |
|
|
142
144
|
|
|
143
145
|
`N` は正の整数で指定します。件数は位置引数の `N` または `-n N` のどちらかで 1 回だけ指定でき、併用や `-n` の繰り返しは使い方の誤りになります。対象のコマンドが指定件数より少なければ、見つかった分をコピーします。`-n` は上記の書式オプションと併用できます。
|
|
144
146
|
|
|
145
147
|
`oops` 自身はコピー対象になりません。直前のコマンドが `oops` だった場合は、その前のコマンドがコピーされます。
|
|
146
148
|
|
|
147
|
-
終了コード: `0` コピーした(または `--print`・`--json` で出力した、`--gist` で上げた)、`1`
|
|
149
|
+
終了コード: `0` コピーした(または `--print`・`--json` で出力した、`--gist` で上げた)、`1` コピーしなかった(記録していない、まだコマンドがない、失敗したコマンドがない、その文字を含むコマンドがない、何も選ばなかった、一時停止中、クリップボードのコマンドが失敗、`--gist` で `gh` が失敗)、`2` 使い方の誤り。
|
|
148
150
|
|
|
149
151
|
### 標準の出力
|
|
150
152
|
|
|
@@ -248,6 +250,27 @@ copied: $ bundle exec rake (85 lines)
|
|
|
248
250
|
|
|
249
251
|
番号を 1 つ、複数(`1 3`)、または範囲(`2-4`)で打つと、実行した順に、`oops 3` と同じ整形とマスクでコピーします。何も打たずに Enter を押すと何もコピーしません。一覧のコマンドもマスク済みです。`-n 20` で 20 件並べます。整形のオプションもそのまま使えます(`oops pick --github`、`oops pick -p | less` など。一覧と `pick>` は標準エラーに出るので、標準出力には本文だけが出ます)。
|
|
250
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
|
+
|
|
251
274
|
### `oops status`
|
|
252
275
|
|
|
253
276
|
`oops status` は `recording`・`paused`・`off`(このシェルが記録されていない、またはログが削除された)のどれかを出力し、記録中のときだけ終了コード `0` を返します。エラーは出さないので、プロンプトやスクリプトから呼べます(例: [starship のカスタムモジュール](https://starship.rs/config/#custom-commands))。呼ぶたびに Ruby が起動するため 0.1〜0.2 秒ほどかかります。`off` のときの詳しい理由は `oops doctor` で分かります。
|
|
@@ -423,11 +446,11 @@ bundle exec exe/oops doctor
|
|
|
423
446
|
|
|
424
447
|
```sh
|
|
425
448
|
gem build oops-cli.gemspec
|
|
426
|
-
gem install ./oops-cli-0.
|
|
449
|
+
gem install ./oops-cli-0.8.0.gem # ファイル名は lib/oops/version.rb に合わせる
|
|
427
450
|
rbenv rehash # rbenv を使う場合のみ
|
|
428
451
|
```
|
|
429
452
|
|
|
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.
|
|
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`)。
|
|
431
454
|
- 変更のたびに入れ直してください。インストールされた gem はコピーで、チェックアウトへのリンクではありません。
|
|
432
455
|
- 削除するには `gem uninstall oops-cli` です。
|
|
433
456
|
- `eval "$(oops init zsh)"` は、プロンプトで打つだけでなく rc ファイルに書いてください。記録されるシェルは rc ファイルを読み直すため、行がないとフックが入りません(`oops doctor` に `hooks: missing` と出ます)。
|
data/README.md
CHANGED
|
@@ -119,6 +119,7 @@ To turn oops off for one shell, start it with `OOPS_DISABLE=1` (for example `OOP
|
|
|
119
119
|
| `oops err` | Copy the last command that exited non-zero, skipping over successful ones |
|
|
120
120
|
| `oops err -n 2` | Copy the last 2 failed commands (oldest first), skipping over successful ones |
|
|
121
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)) |
|
|
122
123
|
| `oops init zsh` / `oops init bash` / `oops init fish` | Print the shell snippet (for `eval`, or `\| source` in fish) |
|
|
123
124
|
| `oops doctor` | Diagnose recording, hooks, clipboard, config and log size |
|
|
124
125
|
| `oops pause` / `oops resume` | Stop and restart recording. While paused, nothing is written to disk |
|
|
@@ -127,24 +128,25 @@ To turn oops off for one shell, start it with `OOPS_DISABLE=1` (for example `OOP
|
|
|
127
128
|
| `oops record -- <shell>` | Internal: runs a shell under the recorder. The snippet calls this |
|
|
128
129
|
| `oops --version`, `oops --help` | Version and usage |
|
|
129
130
|
|
|
130
|
-
Options for `oops`, `oops N`, `oops err` and `oops
|
|
131
|
+
Options for `oops`, `oops N`, `oops err`, `oops pick` and `oops grep`:
|
|
131
132
|
|
|
132
133
|
| Option | What it does |
|
|
133
134
|
|---|---|
|
|
134
|
-
| `-n N` | Copy the last N commands (with `err`, the last N failed commands; with `pick`, list N) |
|
|
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) |
|
|
135
136
|
| `--github` | Format for a GitHub issue or PR comment |
|
|
136
137
|
| `--time` | Add the time each command started as a `# 2026-10-31 19:30:09 +09:00` line |
|
|
137
138
|
| `--output-only` | Leave out the `$ command` line and copy only the output |
|
|
138
139
|
| `-p`, `--print` | Write the text to stdout instead of the clipboard (no `copied:` line) |
|
|
139
140
|
| `--json` | Write the commands as JSON to stdout, for scripts and agents |
|
|
140
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 |
|
|
141
143
|
| `--show-secrets` | Do not mask secrets and do not apply the replace table |
|
|
142
144
|
|
|
143
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.
|
|
144
146
|
|
|
145
147
|
`oops` never copies itself: if the previous command was `oops`, you get the command before it.
|
|
146
148
|
|
|
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.
|
|
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.
|
|
148
150
|
|
|
149
151
|
### Default output
|
|
150
152
|
|
|
@@ -248,6 +250,27 @@ copied: $ bundle exec rake (85 lines)
|
|
|
248
250
|
|
|
249
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).
|
|
250
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
|
+
|
|
251
274
|
### `oops status`
|
|
252
275
|
|
|
253
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`.
|
|
@@ -423,11 +446,11 @@ To try it as your shell does, build and install the gem into the Ruby you are us
|
|
|
423
446
|
|
|
424
447
|
```sh
|
|
425
448
|
gem build oops-cli.gemspec
|
|
426
|
-
gem install ./oops-cli-0.
|
|
449
|
+
gem install ./oops-cli-0.8.0.gem # the file name follows lib/oops/version.rb
|
|
427
450
|
rbenv rehash # only with rbenv
|
|
428
451
|
```
|
|
429
452
|
|
|
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.
|
|
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`.
|
|
431
454
|
- Reinstall after every change. The installed gem is a copy, not a link to your checkout.
|
|
432
455
|
- To remove it: `gem uninstall oops-cli`.
|
|
433
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`).
|
data/lib/oops/cli.rb
CHANGED
|
@@ -11,7 +11,7 @@ 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, :pick)
|
|
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
17
|
# --json has its own shape, so the Markdown formatting options make no
|
|
@@ -48,10 +48,12 @@ module Oops
|
|
|
48
48
|
options = { github: false, show_secrets: false, time: false, output_only: false, print: false,
|
|
49
49
|
json: false, gist: false }
|
|
50
50
|
count = nil
|
|
51
|
+
pick = false
|
|
51
52
|
parser = OptionParser.new do |o|
|
|
52
|
-
o.banner = "Usage: oops [N | err | pick] [-n N] [options]\n " \
|
|
53
|
+
o.banner = "Usage: oops [N | err | pick | grep TEXT] [-n N] [options]\n " \
|
|
53
54
|
"oops init <shell> | pause | resume | status | clear [--all] | doctor"
|
|
54
|
-
o.on("-n N", "Copy the last N commands (with err, last N failures;
|
|
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|
|
|
55
57
|
raise UsageError, COUNT_REPEATED if count
|
|
56
58
|
|
|
57
59
|
count = positive(v, "-n")
|
|
@@ -63,6 +65,7 @@ module Oops
|
|
|
63
65
|
o.on("-p", "--print", "Write the text to stdout instead of the clipboard") { options[:print] = true }
|
|
64
66
|
o.on("--json", "Write the commands as JSON to stdout") { options[:json] = true }
|
|
65
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 }
|
|
66
69
|
o.on("-v", "--version", "Print version and exit") do
|
|
67
70
|
stdout.puts "oops #{VERSION}"
|
|
68
71
|
return 0
|
|
@@ -72,7 +75,7 @@ module Oops
|
|
|
72
75
|
return 0
|
|
73
76
|
end
|
|
74
77
|
end
|
|
75
|
-
copy_target = target(parser.parse(argv), count: count)
|
|
78
|
+
copy_target = target(parser.parse(argv), count: count, pick: pick)
|
|
76
79
|
check_conflicts(options)
|
|
77
80
|
copy(copy_target, options)
|
|
78
81
|
rescue OptionParser::ParseError, UsageError => e
|
|
@@ -107,18 +110,33 @@ module Oops
|
|
|
107
110
|
# Count comes from either a positional N or -n N. "err" filters the
|
|
108
111
|
# selection to failed commands; without a count, one command is copied.
|
|
109
112
|
# "pick" lists the last count commands (Picker::COUNT by default) and
|
|
110
|
-
# copies the ones the user chooses.
|
|
111
|
-
|
|
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
|
|
112
119
|
raise UsageError, "unexpected argument: #{args[1]}" if args.size > 1
|
|
113
120
|
|
|
114
121
|
arg = args.first
|
|
115
|
-
return
|
|
116
|
-
return
|
|
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"
|
|
117
124
|
|
|
118
125
|
raise UsageError, "unknown command: #{arg}" unless arg.match?(/\A[+-]?\d/)
|
|
119
126
|
raise UsageError, COUNT_REPEATED if count
|
|
120
127
|
|
|
121
|
-
|
|
128
|
+
copy_target(count: positive(arg, "N"))
|
|
129
|
+
end
|
|
130
|
+
|
|
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?
|
|
134
|
+
|
|
135
|
+
copy_target(count: count || (pick ? Picker::COUNT : 1), pick: pick, containing: text)
|
|
136
|
+
end
|
|
137
|
+
|
|
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)
|
|
122
140
|
end
|
|
123
141
|
|
|
124
142
|
def copy(target, options)
|
|
@@ -127,8 +145,8 @@ module Oops
|
|
|
127
145
|
|
|
128
146
|
config = Config.load(env: env)
|
|
129
147
|
config.warnings.each { |w| stderr.puts "oops: warning: #{w}" }
|
|
130
|
-
records = log.last(target.count, failed_only: target.failed_only)
|
|
131
|
-
raise Failure, (target
|
|
148
|
+
records = log.last(target.count, failed_only: target.failed_only, containing: target.containing)
|
|
149
|
+
raise Failure, not_found(target) if records.empty?
|
|
132
150
|
|
|
133
151
|
home = env["HOME"].to_s.empty? ? Dir.home : env["HOME"]
|
|
134
152
|
records = pick(records, config: config, home: home, show_secrets: options[:show_secrets]) if target.pick
|
|
@@ -158,6 +176,13 @@ module Oops
|
|
|
158
176
|
0
|
|
159
177
|
end
|
|
160
178
|
|
|
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
|
|
184
|
+
end
|
|
185
|
+
|
|
161
186
|
# `oops pick`: the list and the prompt go to stderr, so `oops pick -p`
|
|
162
187
|
# and `--json` keep stdout for the copied text. The answer is read from
|
|
163
188
|
# stdin, which also lets a script pipe the numbers in.
|
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,8 +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
|
+
/(?<![A-Za-z0-9_])hf_[A-Za-z0-9]{16,}(?![A-Za-z0-9_])/, # Hugging Face access tokens
|
|
20
21
|
/(?<![A-Za-z0-9_])(?:dop|doo|dor)_v1_[0-9a-f]{64}(?![A-Za-z0-9_])/, # DigitalOcean API tokens
|
|
21
|
-
|
|
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
|
|
22
29
|
/\bnpm_[A-Za-z0-9]{36}/, # npm tokens
|
|
23
30
|
%r{hooks\.slack\.com/services/(?<secret>[A-Za-z0-9/]+)}, # Slack webhook URLs
|
|
24
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/version.rb
CHANGED