clipboard-stash 0.1.0__tar.gz
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.
- clipboard_stash-0.1.0/LICENSE +21 -0
- clipboard_stash-0.1.0/MANIFEST.in +3 -0
- clipboard_stash-0.1.0/PKG-INFO +188 -0
- clipboard_stash-0.1.0/README.md +158 -0
- clipboard_stash-0.1.0/README.zh-CN.md +145 -0
- clipboard_stash-0.1.0/clipboard_cli/__init__.py +16 -0
- clipboard_stash-0.1.0/clipboard_cli/__main__.py +8 -0
- clipboard_stash-0.1.0/clipboard_cli/cli.py +1024 -0
- clipboard_stash-0.1.0/clipboard_cli/keypress.py +86 -0
- clipboard_stash-0.1.0/clipboard_cli/watch.py +67 -0
- clipboard_stash-0.1.0/clipboard_stash.egg-info/PKG-INFO +188 -0
- clipboard_stash-0.1.0/clipboard_stash.egg-info/SOURCES.txt +17 -0
- clipboard_stash-0.1.0/clipboard_stash.egg-info/dependency_links.txt +1 -0
- clipboard_stash-0.1.0/clipboard_stash.egg-info/entry_points.txt +2 -0
- clipboard_stash-0.1.0/clipboard_stash.egg-info/requires.txt +4 -0
- clipboard_stash-0.1.0/clipboard_stash.egg-info/top_level.txt +1 -0
- clipboard_stash-0.1.0/pyproject.toml +42 -0
- clipboard_stash-0.1.0/setup.cfg +4 -0
- clipboard_stash-0.1.0/tests/test_clipboard.py +322 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 neo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: clipboard-stash
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An fzf-powered clipboard history for the command line
|
|
5
|
+
Author-email: neo <qqiwei@users.noreply.github.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/qqiwei/cli-toolkit/tree/main/packages/clipboard
|
|
8
|
+
Project-URL: Repository, https://github.com/qqiwei/cli-toolkit
|
|
9
|
+
Project-URL: Issues, https://github.com/qqiwei/cli-toolkit/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/qqiwei/cli-toolkit/commits/main/packages/clipboard
|
|
11
|
+
Keywords: clipboard,fzf,cli,productivity
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Topic :: Utilities
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
28
|
+
Requires-Dist: twine>=5.0; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# clipboard
|
|
32
|
+
|
|
33
|
+
**English** | [简体中文](README.zh-CN.md)
|
|
34
|
+
|
|
35
|
+
An fzf-powered clipboard history for the command line. It keeps entries in a
|
|
36
|
+
plain JSON Lines file, captures the current clipboard, and lets you fuzzy-pick
|
|
37
|
+
one to copy back.
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
clipboard # capture the current clipboard, pick history, copy
|
|
41
|
+
clipboard hello # add hello and copy it
|
|
42
|
+
clipboard -l # list history, newest first
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The command is often aliased to `cb`:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
alias cb=clipboard
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Why
|
|
52
|
+
|
|
53
|
+
System clipboard managers are graphical. `clipboard` gives you the same
|
|
54
|
+
idea in a terminal: every invocation captures the current clipboard, fzf
|
|
55
|
+
shows the history, and Enter copies the selected entry back. Multi-line text
|
|
56
|
+
is preserved exactly.
|
|
57
|
+
|
|
58
|
+
## Requirements
|
|
59
|
+
|
|
60
|
+
- Python 3.11+
|
|
61
|
+
- `fzf` for the fuzzy picker (optional; without it you get a numbered picker)
|
|
62
|
+
- a clipboard tool:
|
|
63
|
+
- macOS: `pbcopy` / `pbpaste` (built in)
|
|
64
|
+
- Linux: `wl-copy` / `wl-paste` (Wayland), or `xclip` / `xsel` (X11)
|
|
65
|
+
- Windows: `clip` / PowerShell `Get-Clipboard`
|
|
66
|
+
- `readline` is optional and only used for single-line editing when fzf is absent
|
|
67
|
+
|
|
68
|
+
Without a clipboard writer, the selected text is printed instead. Without a
|
|
69
|
+
clipboard reader, `-c` and the automatic capture in the default picker are
|
|
70
|
+
skipped.
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
From a source checkout:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
git clone git@github.com:qqiwei/cli-toolkit.git
|
|
78
|
+
cd cli-toolkit/packages/clipboard
|
|
79
|
+
pipx install --editable . # command available as `clipboard`
|
|
80
|
+
# or run it without installing:
|
|
81
|
+
./clipboard --version
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Usage
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
clipboard # capture clipboard, pick and copy
|
|
88
|
+
clipboard TEXT... # add text and copy it
|
|
89
|
+
clipboard -c # capture clipboard into history once
|
|
90
|
+
clipboard -c on # start the background watcher
|
|
91
|
+
clipboard -c off # stop the background watcher
|
|
92
|
+
clipboard -c state # show whether the watcher is running
|
|
93
|
+
clipboard -l # list entries, newest first
|
|
94
|
+
clipboard -l PATTERN # list entries containing PATTERN
|
|
95
|
+
clipboard -d # delete repeatedly; Esc quits
|
|
96
|
+
clipboard -d PATTERN # delete every entry containing PATTERN
|
|
97
|
+
clipboard -e # edit repeatedly; Esc quits
|
|
98
|
+
clipboard -e OLD NEW # replace OLD with NEW in every entry
|
|
99
|
+
clipboard -p # print the history path
|
|
100
|
+
clipboard -p PATH # copy history there and use PATH from now on
|
|
101
|
+
clipboard -v # print the version
|
|
102
|
+
clipboard -h # help plus dependency status
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Arguments are joined with single spaces. A newline inside one argument stays
|
|
106
|
+
part of that one entry; clipboard text is not split into separate entries.
|
|
107
|
+
|
|
108
|
+
Notes:
|
|
109
|
+
|
|
110
|
+
- The default picker captures the current clipboard first. If it is empty, the
|
|
111
|
+
existing history is shown unchanged.
|
|
112
|
+
- `clipboard -c` captures once. `clipboard -c on` starts a detached background
|
|
113
|
+
watcher that polls the clipboard (every 0.5s by default) and appends each new
|
|
114
|
+
value as one entry; `clipboard -c off` stops it; `clipboard -c state` reports
|
|
115
|
+
whether it is running and its pid. The watcher keeps running after the shell
|
|
116
|
+
exits, but is not started automatically at login — run `clipboard -c on` when
|
|
117
|
+
you want it. The pid is kept in `watch.pid` next to the default history file.
|
|
118
|
+
- History is not trimmed automatically. Every captured value stays until you
|
|
119
|
+
delete it with `clipboard -d`.
|
|
120
|
+
- Entries are deduplicated; adding or capturing an existing entry moves it to
|
|
121
|
+
the newest position.
|
|
122
|
+
- `-l` prints one escaped line per entry, so multi-line entries appear as
|
|
123
|
+
`line1\nline2`. This is also what fzf sees and searches.
|
|
124
|
+
- `-d PATTERN` and `-e OLD NEW` use literal substring matching.
|
|
125
|
+
- While picking, Ctrl-D twice deletes the selected entry and Ctrl-E twice
|
|
126
|
+
edits it. The first press shows `delete?> ` / `edit?> ` and a
|
|
127
|
+
`delete> <text>` / `edit> <text>` header; the second press confirms. The
|
|
128
|
+
picker reopens after either action.
|
|
129
|
+
- Single-line entries are edited in the fzf prompt. Multi-line entries open
|
|
130
|
+
`VISUAL` / `EDITOR` on a temporary file.
|
|
131
|
+
- `clipboard -p PATH` follows the same timestamp rules as `mark`: a newer
|
|
132
|
+
destination is refused; an older one asks `[y/N]`.
|
|
133
|
+
- Esc / Ctrl-C exits with status 130; an empty history exits with status 1.
|
|
134
|
+
|
|
135
|
+
## Storage
|
|
136
|
+
|
|
137
|
+
Entries are stored as one JSON string per line, UTF-8, newest last. The file is
|
|
138
|
+
created with mode `0600` and lives outside the repository:
|
|
139
|
+
|
|
140
|
+
| Platform | Default path |
|
|
141
|
+
| --- | --- |
|
|
142
|
+
| macOS | `~/Library/Application Support/clipboard/history.jsonl` |
|
|
143
|
+
| Linux / others | `$XDG_DATA_HOME/clipboard/history.jsonl` (usually `~/.local/share/clipboard/history.jsonl`) |
|
|
144
|
+
|
|
145
|
+
After `clipboard -p PATH`, the chosen path is saved in a `path` file next to
|
|
146
|
+
the default `history.jsonl`. `CLIPBOARD_FILE` overrides the saved path.
|
|
147
|
+
|
|
148
|
+
### Environment variables
|
|
149
|
+
|
|
150
|
+
| Variable | Meaning |
|
|
151
|
+
| --- | --- |
|
|
152
|
+
| `CLIPBOARD_FILE` | Use another history file (`~` is expanded) |
|
|
153
|
+
| `CLIPBOARD_FZF` | Picker command instead of `fzf` |
|
|
154
|
+
| `CLIPBOARD_PROMPT` | Picker prompt (default `clipboard> `) |
|
|
155
|
+
| `CLIPBOARD_COPY` | Command used to write the clipboard |
|
|
156
|
+
| `CLIPBOARD_PASTE` | Command used to read the clipboard |
|
|
157
|
+
| `CLIPBOARD_POLL` | Watcher poll interval in seconds (default `0.5`) |
|
|
158
|
+
| `VISUAL` / `EDITOR` | Editor for multi-line entries |
|
|
159
|
+
|
|
160
|
+
## Development
|
|
161
|
+
|
|
162
|
+
```sh
|
|
163
|
+
cd packages/clipboard
|
|
164
|
+
PYTHONPATH=. python3 -m unittest discover -s tests -v
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Tests use fake clipboard and fzf commands, so they never touch the real
|
|
168
|
+
clipboard or history.
|
|
169
|
+
|
|
170
|
+
## Releasing
|
|
171
|
+
|
|
172
|
+
The version lives in `pyproject.toml` (with a fallback in
|
|
173
|
+
`clipboard_cli/__init__.py`). Push a `clipboard-v*` tag and the workflow runs
|
|
174
|
+
the tests, builds the sdist/wheel, checks the metadata and publishes with PyPI
|
|
175
|
+
trusted publishing (no API token needed):
|
|
176
|
+
|
|
177
|
+
```sh
|
|
178
|
+
git tag clipboard-v0.1.0
|
|
179
|
+
git push origin main --tags
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Before the first release, add a pending publisher on PyPI: project
|
|
183
|
+
`clipboard-stash`, owner `qqiwei`, repository `cli-toolkit`,
|
|
184
|
+
workflow `publish.yml`, environment `pypi`.
|
|
185
|
+
|
|
186
|
+
## License
|
|
187
|
+
|
|
188
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# clipboard
|
|
2
|
+
|
|
3
|
+
**English** | [简体中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
An fzf-powered clipboard history for the command line. It keeps entries in a
|
|
6
|
+
plain JSON Lines file, captures the current clipboard, and lets you fuzzy-pick
|
|
7
|
+
one to copy back.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
clipboard # capture the current clipboard, pick history, copy
|
|
11
|
+
clipboard hello # add hello and copy it
|
|
12
|
+
clipboard -l # list history, newest first
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The command is often aliased to `cb`:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
alias cb=clipboard
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Why
|
|
22
|
+
|
|
23
|
+
System clipboard managers are graphical. `clipboard` gives you the same
|
|
24
|
+
idea in a terminal: every invocation captures the current clipboard, fzf
|
|
25
|
+
shows the history, and Enter copies the selected entry back. Multi-line text
|
|
26
|
+
is preserved exactly.
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
- Python 3.11+
|
|
31
|
+
- `fzf` for the fuzzy picker (optional; without it you get a numbered picker)
|
|
32
|
+
- a clipboard tool:
|
|
33
|
+
- macOS: `pbcopy` / `pbpaste` (built in)
|
|
34
|
+
- Linux: `wl-copy` / `wl-paste` (Wayland), or `xclip` / `xsel` (X11)
|
|
35
|
+
- Windows: `clip` / PowerShell `Get-Clipboard`
|
|
36
|
+
- `readline` is optional and only used for single-line editing when fzf is absent
|
|
37
|
+
|
|
38
|
+
Without a clipboard writer, the selected text is printed instead. Without a
|
|
39
|
+
clipboard reader, `-c` and the automatic capture in the default picker are
|
|
40
|
+
skipped.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
From a source checkout:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
git clone git@github.com:qqiwei/cli-toolkit.git
|
|
48
|
+
cd cli-toolkit/packages/clipboard
|
|
49
|
+
pipx install --editable . # command available as `clipboard`
|
|
50
|
+
# or run it without installing:
|
|
51
|
+
./clipboard --version
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
clipboard # capture clipboard, pick and copy
|
|
58
|
+
clipboard TEXT... # add text and copy it
|
|
59
|
+
clipboard -c # capture clipboard into history once
|
|
60
|
+
clipboard -c on # start the background watcher
|
|
61
|
+
clipboard -c off # stop the background watcher
|
|
62
|
+
clipboard -c state # show whether the watcher is running
|
|
63
|
+
clipboard -l # list entries, newest first
|
|
64
|
+
clipboard -l PATTERN # list entries containing PATTERN
|
|
65
|
+
clipboard -d # delete repeatedly; Esc quits
|
|
66
|
+
clipboard -d PATTERN # delete every entry containing PATTERN
|
|
67
|
+
clipboard -e # edit repeatedly; Esc quits
|
|
68
|
+
clipboard -e OLD NEW # replace OLD with NEW in every entry
|
|
69
|
+
clipboard -p # print the history path
|
|
70
|
+
clipboard -p PATH # copy history there and use PATH from now on
|
|
71
|
+
clipboard -v # print the version
|
|
72
|
+
clipboard -h # help plus dependency status
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Arguments are joined with single spaces. A newline inside one argument stays
|
|
76
|
+
part of that one entry; clipboard text is not split into separate entries.
|
|
77
|
+
|
|
78
|
+
Notes:
|
|
79
|
+
|
|
80
|
+
- The default picker captures the current clipboard first. If it is empty, the
|
|
81
|
+
existing history is shown unchanged.
|
|
82
|
+
- `clipboard -c` captures once. `clipboard -c on` starts a detached background
|
|
83
|
+
watcher that polls the clipboard (every 0.5s by default) and appends each new
|
|
84
|
+
value as one entry; `clipboard -c off` stops it; `clipboard -c state` reports
|
|
85
|
+
whether it is running and its pid. The watcher keeps running after the shell
|
|
86
|
+
exits, but is not started automatically at login — run `clipboard -c on` when
|
|
87
|
+
you want it. The pid is kept in `watch.pid` next to the default history file.
|
|
88
|
+
- History is not trimmed automatically. Every captured value stays until you
|
|
89
|
+
delete it with `clipboard -d`.
|
|
90
|
+
- Entries are deduplicated; adding or capturing an existing entry moves it to
|
|
91
|
+
the newest position.
|
|
92
|
+
- `-l` prints one escaped line per entry, so multi-line entries appear as
|
|
93
|
+
`line1\nline2`. This is also what fzf sees and searches.
|
|
94
|
+
- `-d PATTERN` and `-e OLD NEW` use literal substring matching.
|
|
95
|
+
- While picking, Ctrl-D twice deletes the selected entry and Ctrl-E twice
|
|
96
|
+
edits it. The first press shows `delete?> ` / `edit?> ` and a
|
|
97
|
+
`delete> <text>` / `edit> <text>` header; the second press confirms. The
|
|
98
|
+
picker reopens after either action.
|
|
99
|
+
- Single-line entries are edited in the fzf prompt. Multi-line entries open
|
|
100
|
+
`VISUAL` / `EDITOR` on a temporary file.
|
|
101
|
+
- `clipboard -p PATH` follows the same timestamp rules as `mark`: a newer
|
|
102
|
+
destination is refused; an older one asks `[y/N]`.
|
|
103
|
+
- Esc / Ctrl-C exits with status 130; an empty history exits with status 1.
|
|
104
|
+
|
|
105
|
+
## Storage
|
|
106
|
+
|
|
107
|
+
Entries are stored as one JSON string per line, UTF-8, newest last. The file is
|
|
108
|
+
created with mode `0600` and lives outside the repository:
|
|
109
|
+
|
|
110
|
+
| Platform | Default path |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| macOS | `~/Library/Application Support/clipboard/history.jsonl` |
|
|
113
|
+
| Linux / others | `$XDG_DATA_HOME/clipboard/history.jsonl` (usually `~/.local/share/clipboard/history.jsonl`) |
|
|
114
|
+
|
|
115
|
+
After `clipboard -p PATH`, the chosen path is saved in a `path` file next to
|
|
116
|
+
the default `history.jsonl`. `CLIPBOARD_FILE` overrides the saved path.
|
|
117
|
+
|
|
118
|
+
### Environment variables
|
|
119
|
+
|
|
120
|
+
| Variable | Meaning |
|
|
121
|
+
| --- | --- |
|
|
122
|
+
| `CLIPBOARD_FILE` | Use another history file (`~` is expanded) |
|
|
123
|
+
| `CLIPBOARD_FZF` | Picker command instead of `fzf` |
|
|
124
|
+
| `CLIPBOARD_PROMPT` | Picker prompt (default `clipboard> `) |
|
|
125
|
+
| `CLIPBOARD_COPY` | Command used to write the clipboard |
|
|
126
|
+
| `CLIPBOARD_PASTE` | Command used to read the clipboard |
|
|
127
|
+
| `CLIPBOARD_POLL` | Watcher poll interval in seconds (default `0.5`) |
|
|
128
|
+
| `VISUAL` / `EDITOR` | Editor for multi-line entries |
|
|
129
|
+
|
|
130
|
+
## Development
|
|
131
|
+
|
|
132
|
+
```sh
|
|
133
|
+
cd packages/clipboard
|
|
134
|
+
PYTHONPATH=. python3 -m unittest discover -s tests -v
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Tests use fake clipboard and fzf commands, so they never touch the real
|
|
138
|
+
clipboard or history.
|
|
139
|
+
|
|
140
|
+
## Releasing
|
|
141
|
+
|
|
142
|
+
The version lives in `pyproject.toml` (with a fallback in
|
|
143
|
+
`clipboard_cli/__init__.py`). Push a `clipboard-v*` tag and the workflow runs
|
|
144
|
+
the tests, builds the sdist/wheel, checks the metadata and publishes with PyPI
|
|
145
|
+
trusted publishing (no API token needed):
|
|
146
|
+
|
|
147
|
+
```sh
|
|
148
|
+
git tag clipboard-v0.1.0
|
|
149
|
+
git push origin main --tags
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Before the first release, add a pending publisher on PyPI: project
|
|
153
|
+
`clipboard-stash`, owner `qqiwei`, repository `cli-toolkit`,
|
|
154
|
+
workflow `publish.yml`, environment `pypi`.
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# clipboard
|
|
2
|
+
|
|
3
|
+
[English](README.md) | **简体中文**
|
|
4
|
+
|
|
5
|
+
一个基于 fzf 的命令行剪贴板历史。内容保存在纯文本 JSON Lines 文件里,每次运行
|
|
6
|
+
捕获当前剪贴板,再用 fzf 选择历史条目复制回去。
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
clipboard # 捕获当前剪贴板,选择历史并复制
|
|
10
|
+
clipboard hello # 添加 hello 并复制
|
|
11
|
+
clipboard -l # 按最新在前列出历史
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
通常把它别名为 `cb`:
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
alias cb=clipboard
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 用途
|
|
21
|
+
|
|
22
|
+
系统剪贴板管理器通常是图形界面的。`clipboard` 在终端里提供类似的体验:每次运行
|
|
23
|
+
先捕获当前剪贴板,fzf 展示历史,回车把选中的条目复制回剪贴板。多行文本会原样
|
|
24
|
+
保留。
|
|
25
|
+
|
|
26
|
+
## 依赖
|
|
27
|
+
|
|
28
|
+
- Python 3.11+
|
|
29
|
+
- `fzf`:模糊选择器(可选;没有时退回编号列表)
|
|
30
|
+
- 剪贴板工具:
|
|
31
|
+
- macOS:`pbcopy` / `pbpaste`(系统自带)
|
|
32
|
+
- Linux:`wl-copy` / `wl-paste`(Wayland),或 `xclip` / `xsel`(X11)
|
|
33
|
+
- Windows:`clip` / PowerShell `Get-Clipboard`
|
|
34
|
+
- `readline`:可选,只在没有 fzf 时用于单行编辑
|
|
35
|
+
|
|
36
|
+
没有剪贴板写入工具时,选中的内容会直接打印;没有读取工具时,`-c` 和默认选择器
|
|
37
|
+
里的自动捕获会跳过。
|
|
38
|
+
|
|
39
|
+
## 安装
|
|
40
|
+
|
|
41
|
+
从源码安装:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
git clone git@github.com:qqiwei/cli-toolkit.git
|
|
45
|
+
cd cli-toolkit/packages/clipboard
|
|
46
|
+
pipx install --editable . # 命令名是 clipboard
|
|
47
|
+
# 也可以不安装直接运行:
|
|
48
|
+
./clipboard --version
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 用法
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
clipboard # 捕获剪贴板,选择并复制
|
|
55
|
+
clipboard TEXT... # 添加文本并复制
|
|
56
|
+
clipboard -c # 只把当前剪贴板加入历史一次
|
|
57
|
+
clipboard -c on # 打开后台监听
|
|
58
|
+
clipboard -c off # 关闭后台监听
|
|
59
|
+
clipboard -c state # 查看监听是否在运行
|
|
60
|
+
clipboard -l # 列出历史,最新的在前
|
|
61
|
+
clipboard -l PATTERN # 只列出包含 PATTERN 的条目
|
|
62
|
+
clipboard -d # 连续删除,Esc 退出
|
|
63
|
+
clipboard -d PATTERN # 删除所有包含 PATTERN 的条目
|
|
64
|
+
clipboard -e # 连续编辑,Esc 退出
|
|
65
|
+
clipboard -e OLD NEW # 把所有条目里的 OLD 替换为 NEW
|
|
66
|
+
clipboard -p # 显示历史文件路径
|
|
67
|
+
clipboard -p PATH # 把历史复制到 PATH,以后使用新路径
|
|
68
|
+
clipboard -v # 显示版本
|
|
69
|
+
clipboard -h # 帮助和依赖检查
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
多个参数会用单个空格拼起来。参数里的换行仍属于同一个条目,不会拆成多条。
|
|
73
|
+
|
|
74
|
+
说明:
|
|
75
|
+
|
|
76
|
+
- 默认选择器会先捕获当前剪贴板;如果剪贴板为空,就只展示现有历史。
|
|
77
|
+
- `clipboard -c` 只捕获一次。`clipboard -c on` 会启动一个脱离终端的后台监听,
|
|
78
|
+
默认每 0.5 秒读取一次剪贴板,把每个新值作为一条记录加入历史;`clipboard -c
|
|
79
|
+
off` 停止监听;`clipboard -c state` 查看是否在运行以及 pid。监听进程在 shell
|
|
80
|
+
退出后仍会继续,但不会随登录自动启动——需要时手动运行 `clipboard -c on`。
|
|
81
|
+
pid 保存在默认历史文件旁边的 `watch.pid`。
|
|
82
|
+
- 历史不会自动裁剪;捕获的每条内容都会保留,直到用 `clipboard -d` 删除。
|
|
83
|
+
- 条目会去重;再次添加或捕获已存在的条目会把它移到最新位置。
|
|
84
|
+
- `-l` 每行输出一个转义后的条目,所以多行内容显示为 `line1\nline2`。fzf 看到和
|
|
85
|
+
搜索的也是这个表示。
|
|
86
|
+
- `-d PATTERN` 和 `-e OLD NEW` 都按字面子串匹配。
|
|
87
|
+
- 选择时按两次 Ctrl-D 删除选中条目,按两次 Ctrl-E 编辑它。第一次按下会显示
|
|
88
|
+
`delete?> ` / `edit?> ` 和 `delete> <文本>` / `edit> <文本>` 标题;第二次才
|
|
89
|
+
执行。操作后选择器会重新打开。
|
|
90
|
+
- 单行条目在 fzf 输入框里编辑;多行条目会用 `VISUAL` / `EDITOR` 打开临时文件。
|
|
91
|
+
- `clipboard -p PATH` 的时间戳规则和 `mark` 一致:目标更新时拒绝覆盖,目标更早
|
|
92
|
+
时询问 `[y/N]`。
|
|
93
|
+
- Esc / Ctrl-C 退出码 130;历史为空时退出码 1。
|
|
94
|
+
|
|
95
|
+
## 存储
|
|
96
|
+
|
|
97
|
+
每条记录是一个 JSON 字符串,一行一条,UTF-8,最新的在最后。文件权限 `0600`,
|
|
98
|
+
放在仓库之外:
|
|
99
|
+
|
|
100
|
+
| 平台 | 默认路径 |
|
|
101
|
+
| --- | --- |
|
|
102
|
+
| macOS | `~/Library/Application Support/clipboard/history.jsonl` |
|
|
103
|
+
| Linux / 其他 | `$XDG_DATA_HOME/clipboard/history.jsonl`(通常是 `~/.local/share/clipboard/history.jsonl`) |
|
|
104
|
+
|
|
105
|
+
执行 `clipboard -p PATH` 后,路径会保存到默认 `history.jsonl` 旁边的 `path`
|
|
106
|
+
文件。`CLIPBOARD_FILE` 的优先级高于保存的路径。
|
|
107
|
+
|
|
108
|
+
### 环境变量
|
|
109
|
+
|
|
110
|
+
| 变量 | 作用 |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| `CLIPBOARD_FILE` | 换一个历史文件(支持 `~`) |
|
|
113
|
+
| `CLIPBOARD_FZF` | 指定别的选择器,代替 `fzf` |
|
|
114
|
+
| `CLIPBOARD_PROMPT` | 选择器提示符(默认 `clipboard> `) |
|
|
115
|
+
| `CLIPBOARD_COPY` | 写剪贴板的命令 |
|
|
116
|
+
| `CLIPBOARD_PASTE` | 读剪贴板的命令 |
|
|
117
|
+
| `CLIPBOARD_POLL` | 后台监听轮询间隔(秒,默认 `0.5`) |
|
|
118
|
+
| `VISUAL` / `EDITOR` | 多行条目的编辑器 |
|
|
119
|
+
|
|
120
|
+
## 开发
|
|
121
|
+
|
|
122
|
+
```sh
|
|
123
|
+
cd packages/clipboard
|
|
124
|
+
PYTHONPATH=. python3 -m unittest discover -s tests -v
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
测试使用假的剪贴板和 fzf 命令,不会碰真实剪贴板或历史。
|
|
128
|
+
|
|
129
|
+
## 发布
|
|
130
|
+
|
|
131
|
+
版本号写在 `pyproject.toml`(`clipboard_cli/__init__.py` 里有回退值)。推一个
|
|
132
|
+
`clipboard-v*` tag,workflow 会跑测试、构建 sdist/wheel、检查元数据,并通过
|
|
133
|
+
PyPI trusted publishing 发布(不需要 API token):
|
|
134
|
+
|
|
135
|
+
```sh
|
|
136
|
+
git tag clipboard-v0.1.0
|
|
137
|
+
git push origin main --tags
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
首次发布前,在 PyPI 添加 pending publisher:项目 `clipboard-stash`,owner
|
|
141
|
+
`qqiwei`,仓库 `cli-toolkit`,workflow `publish.yml`,环境 `pypi`。
|
|
142
|
+
|
|
143
|
+
## 许可证
|
|
144
|
+
|
|
145
|
+
MIT,见 [LICENSE](LICENSE)。
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""clipboard - an fzf-powered clipboard history."""
|
|
2
|
+
|
|
3
|
+
import tomllib
|
|
4
|
+
from importlib.metadata import PackageNotFoundError, version as _dist_version
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
_pyproject = Path(__file__).resolve().parents[1] / "pyproject.toml"
|
|
9
|
+
__version__ = tomllib.loads(_pyproject.read_text(encoding="utf-8"))["project"][
|
|
10
|
+
"version"
|
|
11
|
+
]
|
|
12
|
+
except (FileNotFoundError, KeyError, tomllib.TOMLDecodeError):
|
|
13
|
+
try:
|
|
14
|
+
__version__ = _dist_version("clipboard-stash")
|
|
15
|
+
except PackageNotFoundError:
|
|
16
|
+
__version__ = "0.1.0"
|