shist 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.
- shist-0.1.0/.github/workflows/ci.yml +21 -0
- shist-0.1.0/.github/workflows/publish.yml +40 -0
- shist-0.1.0/.gitignore +9 -0
- shist-0.1.0/LICENSE +21 -0
- shist-0.1.0/PKG-INFO +101 -0
- shist-0.1.0/README.md +73 -0
- shist-0.1.0/pyproject.toml +51 -0
- shist-0.1.0/setup.cfg +4 -0
- shist-0.1.0/shell/shist.sh +14 -0
- shist-0.1.0/src/shist/__init__.py +11 -0
- shist-0.1.0/src/shist/__main__.py +112 -0
- shist-0.1.0/src/shist/app.py +335 -0
- shist-0.1.0/src/shist/clipboard.py +10 -0
- shist-0.1.0/src/shist/fuzzy.py +35 -0
- shist-0.1.0/src/shist/history_source.py +96 -0
- shist-0.1.0/src/shist.egg-info/PKG-INFO +101 -0
- shist-0.1.0/src/shist.egg-info/SOURCES.txt +24 -0
- shist-0.1.0/src/shist.egg-info/dependency_links.txt +1 -0
- shist-0.1.0/src/shist.egg-info/entry_points.txt +2 -0
- shist-0.1.0/src/shist.egg-info/requires.txt +6 -0
- shist-0.1.0/src/shist.egg-info/scm_file_list.json +20 -0
- shist-0.1.0/src/shist.egg-info/scm_version.json +8 -0
- shist-0.1.0/src/shist.egg-info/top_level.txt +1 -0
- shist-0.1.0/tests/test_app.py +145 -0
- shist-0.1.0/tests/test_fuzzy.py +23 -0
- shist-0.1.0/tests/test_history_source.py +46 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
with:
|
|
14
|
+
fetch-depth: 0 # setuptools_scm needs tag history to compute a version
|
|
15
|
+
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: "3.12"
|
|
19
|
+
|
|
20
|
+
- run: pip install ".[dev]"
|
|
21
|
+
- run: pytest -q
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v[0-9]+.[0-9]+.[0-9]+"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
with:
|
|
14
|
+
fetch-depth: 0
|
|
15
|
+
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: "3.12"
|
|
19
|
+
|
|
20
|
+
- run: pip install ".[dev]"
|
|
21
|
+
- run: pytest -q
|
|
22
|
+
|
|
23
|
+
publish:
|
|
24
|
+
needs: test
|
|
25
|
+
runs-on: ubuntu-latest
|
|
26
|
+
permissions:
|
|
27
|
+
id-token: write # required for PyPI trusted publishing (OIDC) -- no API token needed
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/checkout@v4
|
|
30
|
+
with:
|
|
31
|
+
fetch-depth: 0 # setuptools_scm derives the version from the pushed tag
|
|
32
|
+
|
|
33
|
+
- uses: actions/setup-python@v5
|
|
34
|
+
with:
|
|
35
|
+
python-version: "3.12"
|
|
36
|
+
|
|
37
|
+
- run: pip install build
|
|
38
|
+
- run: python -m build
|
|
39
|
+
|
|
40
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
shist-0.1.0/.gitignore
ADDED
shist-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 matplo
|
|
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.
|
shist-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: shist
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: TUI to pick commands from your shell history and copy them to the clipboard
|
|
5
|
+
Author-email: matplo <noksolp@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/matplo/shist
|
|
8
|
+
Project-URL: Repository, https://github.com/matplo/shist
|
|
9
|
+
Project-URL: Issues, https://github.com/matplo/shist/issues
|
|
10
|
+
Keywords: shell,history,tui,clipboard,bash,zsh
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Environment :: Console :: Curses
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: POSIX
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Topic :: Utilities
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: textual>=0.60
|
|
23
|
+
Requires-Dist: pyperclip>=1.8
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# shist
|
|
30
|
+
|
|
31
|
+
A small TUI for picking commands out of your shell history and copying them
|
|
32
|
+
to the clipboard. Targets bash primarily; zsh is supported the same way.
|
|
33
|
+
|
|
34
|
+
## How it works
|
|
35
|
+
|
|
36
|
+
- **In bash/zsh, after sourcing the shell integration** (recommended): `shist`
|
|
37
|
+
is a shell function that pipes your shell's own `history` builtin into the
|
|
38
|
+
tool. That's the *live*, in-memory history of the current session,
|
|
39
|
+
including anything you typed that hasn't been flushed to a history file
|
|
40
|
+
yet.
|
|
41
|
+
- **Standalone** (no shell integration, or in a shell without a `history`
|
|
42
|
+
builtin): running `shist` directly reads a history file instead —
|
|
43
|
+
`--file PATH`, or `$HISTFILE`, or `~/.bash_history` / `~/.zsh_history`
|
|
44
|
+
depending on `--shell`/`$SHELL`. This can miss very recent commands the
|
|
45
|
+
live shell hasn't written to disk yet.
|
|
46
|
+
|
|
47
|
+
## Install
|
|
48
|
+
|
|
49
|
+
Dependencies are installed into the `dev` henv environment rather than a
|
|
50
|
+
project-local venv:
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
henv -n dev --run pip install -e /Users/ploskon/devel/shist
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Then add the shell integration to your `.bashrc` and/or `.zshrc`:
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
source /Users/ploskon/devel/shist/shell/shist.sh
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Open a new shell (or `source` your rc file) and run `shist`.
|
|
63
|
+
|
|
64
|
+
## Using it
|
|
65
|
+
|
|
66
|
+
There are three panels; `Tab` cycles through them: **search** → **history**
|
|
67
|
+
→ **selection** → back to **search**. This keeps typing fully separate from
|
|
68
|
+
the single-key list commands — `c`, `d`, `-`, `[`, `]` are always literal
|
|
69
|
+
query text while you're in the search panel, and only act as commands once
|
|
70
|
+
you've tabbed into history or selection.
|
|
71
|
+
|
|
72
|
+
**Search** (active on start):
|
|
73
|
+
- Type to filter (fuzzy substring match); `Backspace` edits it.
|
|
74
|
+
- `↑`/`↓` (`Ctrl+P`/`Ctrl+N`) still browse the history list live;
|
|
75
|
+
`Shift+↑`/`Shift+↓` page through it.
|
|
76
|
+
- `Tab` moves to the history panel.
|
|
77
|
+
|
|
78
|
+
**History panel** (browse & add):
|
|
79
|
+
- `↑`/`↓` move the highlight, not wrapping past either end;
|
|
80
|
+
`Shift+↑`/`Shift+↓` move a page at a time.
|
|
81
|
+
- `c` adds the highlighted command to the selection, at the end.
|
|
82
|
+
- `Tab` moves to the selection panel.
|
|
83
|
+
|
|
84
|
+
**Selection panel** (the running list of what you've added, in order):
|
|
85
|
+
- `↑`/`↓` move the highlight, not wrapping past either end;
|
|
86
|
+
`Shift+↑`/`Shift+↓` move a page at a time.
|
|
87
|
+
- `d` or `-` removes the highlighted entry.
|
|
88
|
+
- `[` / `]` move the highlighted entry earlier/later.
|
|
89
|
+
- `Tab` moves back to search.
|
|
90
|
+
|
|
91
|
+
**Any panel:**
|
|
92
|
+
- `Enter` confirms: copies the selection, newline-joined in order; with
|
|
93
|
+
nothing added, copies just the highlighted history entry.
|
|
94
|
+
- `Esc` / `Ctrl+C` cancels without copying anything.
|
|
95
|
+
|
|
96
|
+
## Known limitations
|
|
97
|
+
|
|
98
|
+
- A custom `HISTTIMEFORMAT` in bash gets treated as part of the command text
|
|
99
|
+
when reading piped `history` output — not specially parsed out.
|
|
100
|
+
- Plain POSIX `sh`/`dash` has no `history` builtin, so there's no live-history
|
|
101
|
+
mode for it; only the standalone/file-fallback mode applies.
|
shist-0.1.0/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# shist
|
|
2
|
+
|
|
3
|
+
A small TUI for picking commands out of your shell history and copying them
|
|
4
|
+
to the clipboard. Targets bash primarily; zsh is supported the same way.
|
|
5
|
+
|
|
6
|
+
## How it works
|
|
7
|
+
|
|
8
|
+
- **In bash/zsh, after sourcing the shell integration** (recommended): `shist`
|
|
9
|
+
is a shell function that pipes your shell's own `history` builtin into the
|
|
10
|
+
tool. That's the *live*, in-memory history of the current session,
|
|
11
|
+
including anything you typed that hasn't been flushed to a history file
|
|
12
|
+
yet.
|
|
13
|
+
- **Standalone** (no shell integration, or in a shell without a `history`
|
|
14
|
+
builtin): running `shist` directly reads a history file instead —
|
|
15
|
+
`--file PATH`, or `$HISTFILE`, or `~/.bash_history` / `~/.zsh_history`
|
|
16
|
+
depending on `--shell`/`$SHELL`. This can miss very recent commands the
|
|
17
|
+
live shell hasn't written to disk yet.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
Dependencies are installed into the `dev` henv environment rather than a
|
|
22
|
+
project-local venv:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
henv -n dev --run pip install -e /Users/ploskon/devel/shist
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Then add the shell integration to your `.bashrc` and/or `.zshrc`:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
source /Users/ploskon/devel/shist/shell/shist.sh
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Open a new shell (or `source` your rc file) and run `shist`.
|
|
35
|
+
|
|
36
|
+
## Using it
|
|
37
|
+
|
|
38
|
+
There are three panels; `Tab` cycles through them: **search** → **history**
|
|
39
|
+
→ **selection** → back to **search**. This keeps typing fully separate from
|
|
40
|
+
the single-key list commands — `c`, `d`, `-`, `[`, `]` are always literal
|
|
41
|
+
query text while you're in the search panel, and only act as commands once
|
|
42
|
+
you've tabbed into history or selection.
|
|
43
|
+
|
|
44
|
+
**Search** (active on start):
|
|
45
|
+
- Type to filter (fuzzy substring match); `Backspace` edits it.
|
|
46
|
+
- `↑`/`↓` (`Ctrl+P`/`Ctrl+N`) still browse the history list live;
|
|
47
|
+
`Shift+↑`/`Shift+↓` page through it.
|
|
48
|
+
- `Tab` moves to the history panel.
|
|
49
|
+
|
|
50
|
+
**History panel** (browse & add):
|
|
51
|
+
- `↑`/`↓` move the highlight, not wrapping past either end;
|
|
52
|
+
`Shift+↑`/`Shift+↓` move a page at a time.
|
|
53
|
+
- `c` adds the highlighted command to the selection, at the end.
|
|
54
|
+
- `Tab` moves to the selection panel.
|
|
55
|
+
|
|
56
|
+
**Selection panel** (the running list of what you've added, in order):
|
|
57
|
+
- `↑`/`↓` move the highlight, not wrapping past either end;
|
|
58
|
+
`Shift+↑`/`Shift+↓` move a page at a time.
|
|
59
|
+
- `d` or `-` removes the highlighted entry.
|
|
60
|
+
- `[` / `]` move the highlighted entry earlier/later.
|
|
61
|
+
- `Tab` moves back to search.
|
|
62
|
+
|
|
63
|
+
**Any panel:**
|
|
64
|
+
- `Enter` confirms: copies the selection, newline-joined in order; with
|
|
65
|
+
nothing added, copies just the highlighted history entry.
|
|
66
|
+
- `Esc` / `Ctrl+C` cancels without copying anything.
|
|
67
|
+
|
|
68
|
+
## Known limitations
|
|
69
|
+
|
|
70
|
+
- A custom `HISTTIMEFORMAT` in bash gets treated as part of the command text
|
|
71
|
+
when reading piped `history` output — not specially parsed out.
|
|
72
|
+
- Plain POSIX `sh`/`dash` has no `history` builtin, so there's no live-history
|
|
73
|
+
mode for it; only the standalone/file-fallback mode applies.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "shist"
|
|
3
|
+
dynamic = ["version"]
|
|
4
|
+
description = "TUI to pick commands from your shell history and copy them to the clipboard"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.9"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "matplo", email = "noksolp@gmail.com" },
|
|
11
|
+
]
|
|
12
|
+
keywords = ["shell", "history", "tui", "clipboard", "bash", "zsh"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Environment :: Console",
|
|
15
|
+
"Environment :: Console :: Curses",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Operating System :: MacOS",
|
|
18
|
+
"Operating System :: POSIX",
|
|
19
|
+
"Operating System :: POSIX :: Linux",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Topic :: Utilities",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"textual>=0.60",
|
|
25
|
+
"pyperclip>=1.8",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/matplo/shist"
|
|
30
|
+
Repository = "https://github.com/matplo/shist"
|
|
31
|
+
Issues = "https://github.com/matplo/shist/issues"
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
dev = ["pytest", "pytest-asyncio"]
|
|
35
|
+
|
|
36
|
+
[project.scripts]
|
|
37
|
+
shist = "shist.__main__:main"
|
|
38
|
+
|
|
39
|
+
[build-system]
|
|
40
|
+
requires = ["setuptools>=68", "setuptools_scm>=8"]
|
|
41
|
+
build-backend = "setuptools.build_meta"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["src"]
|
|
45
|
+
|
|
46
|
+
[tool.setuptools_scm]
|
|
47
|
+
# Version is derived from git tags (e.g. tag "v0.1.0" -> version "0.1.0"),
|
|
48
|
+
# which is what lets the publish workflow just be "push a tag".
|
|
49
|
+
|
|
50
|
+
[tool.pytest.ini_options]
|
|
51
|
+
asyncio_mode = "auto"
|
shist-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# shist shell integration — works in both bash and zsh, since both provide
|
|
2
|
+
# a `history` builtin with the same output shape and support this function
|
|
3
|
+
# syntax.
|
|
4
|
+
#
|
|
5
|
+
# Source this from your .bashrc / .zshrc, e.g.:
|
|
6
|
+
# source /Users/ploskon/devel/shist/shell/shist.sh
|
|
7
|
+
#
|
|
8
|
+
# Then just run `shist` in either shell to pick a command from its live
|
|
9
|
+
# history (including anything typed this session, not yet written to disk)
|
|
10
|
+
# and copy it to the clipboard.
|
|
11
|
+
|
|
12
|
+
shist() {
|
|
13
|
+
history | henv -n dev --run shist "$@"
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""shist — TUI shell-history picker with clipboard copy."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
__version__ = version("shist")
|
|
7
|
+
except PackageNotFoundError:
|
|
8
|
+
# Not installed (e.g. running straight from a source checkout without
|
|
9
|
+
# `pip install -e .`) -- version comes from setuptools_scm/git tags at
|
|
10
|
+
# build time, so there's nothing meaningful to report here.
|
|
11
|
+
__version__ = "0.0.0+unknown"
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""CLI entry point: figures out where history comes from, hands it to the
|
|
2
|
+
TUI, and copies the result to the clipboard."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from . import clipboard
|
|
11
|
+
from .history_source import parse_history_output, read_history
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _read_piped_history() -> list[str]:
|
|
15
|
+
"""Consume the piped `history` output. Stdin is left as-is here — the
|
|
16
|
+
real terminal isn't reclaimed until we know there's something to show
|
|
17
|
+
(see `_reclaim_terminal`), so an empty/no-history case never has to
|
|
18
|
+
touch `/dev/tty` at all.
|
|
19
|
+
"""
|
|
20
|
+
raw = sys.stdin.read()
|
|
21
|
+
return parse_history_output(raw)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _reclaim_terminal() -> bool:
|
|
25
|
+
"""Hand the controlling terminal back to fd 0 so the TUI can read
|
|
26
|
+
keystrokes from it.
|
|
27
|
+
|
|
28
|
+
`shist` is normally invoked as `history | shist`, which makes stdin the
|
|
29
|
+
*data* channel rather than the keyboard. Once that data's been read, we
|
|
30
|
+
reopen stdin from the controlling terminal — the same trick tools like
|
|
31
|
+
fzf use to stay interactive while accepting piped input. Returns False
|
|
32
|
+
(instead of raising) when there's no controlling terminal to reclaim,
|
|
33
|
+
e.g. running with no tty at all.
|
|
34
|
+
|
|
35
|
+
Textual's driver reads the terminal fd off `sys.__stdin__` specifically,
|
|
36
|
+
not `sys.stdin` — so both names have to be repointed at the reopened
|
|
37
|
+
file, or the driver keeps holding the old, now-closed pipe object and
|
|
38
|
+
raises "I/O operation on closed file".
|
|
39
|
+
"""
|
|
40
|
+
sys.stdin.close()
|
|
41
|
+
try:
|
|
42
|
+
tty = open("/dev/tty")
|
|
43
|
+
except OSError as exc:
|
|
44
|
+
print(f"shist: no controlling terminal available ({exc})", file=sys.stderr)
|
|
45
|
+
return False
|
|
46
|
+
sys.stdin = tty
|
|
47
|
+
sys.__stdin__ = tty
|
|
48
|
+
return True
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
52
|
+
from . import __version__
|
|
53
|
+
|
|
54
|
+
parser = argparse.ArgumentParser(
|
|
55
|
+
prog="shist",
|
|
56
|
+
description="Pick a command from shell history and copy it to the clipboard.",
|
|
57
|
+
)
|
|
58
|
+
parser.add_argument(
|
|
59
|
+
"-V", "--version", action="version", version=f"shist {__version__}"
|
|
60
|
+
)
|
|
61
|
+
parser.add_argument(
|
|
62
|
+
"query", nargs="?", default="", help="initial filter text"
|
|
63
|
+
)
|
|
64
|
+
parser.add_argument(
|
|
65
|
+
"--shell",
|
|
66
|
+
choices=["bash", "zsh"],
|
|
67
|
+
default=None,
|
|
68
|
+
help="which shell's history file to read from, when not given piped history "
|
|
69
|
+
"(default: guessed from $SHELL)",
|
|
70
|
+
)
|
|
71
|
+
parser.add_argument(
|
|
72
|
+
"--file",
|
|
73
|
+
type=Path,
|
|
74
|
+
default=None,
|
|
75
|
+
help="explicit history file to read from, when not given piped history",
|
|
76
|
+
)
|
|
77
|
+
return parser
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def main(argv: list[str] | None = None) -> int:
|
|
81
|
+
args = build_parser().parse_args(argv)
|
|
82
|
+
|
|
83
|
+
piped = not sys.stdin.isatty()
|
|
84
|
+
if piped:
|
|
85
|
+
commands = _read_piped_history()
|
|
86
|
+
else:
|
|
87
|
+
commands = read_history(shell=args.shell, file=args.file)
|
|
88
|
+
|
|
89
|
+
if not commands:
|
|
90
|
+
print("shist: no history found", file=sys.stderr)
|
|
91
|
+
return 1
|
|
92
|
+
|
|
93
|
+
if piped and not _reclaim_terminal():
|
|
94
|
+
return 1
|
|
95
|
+
|
|
96
|
+
# Imported lazily: constructing the Textual App touches the terminal, so
|
|
97
|
+
# this only happens once we know there's something to show.
|
|
98
|
+
from .app import run_picker
|
|
99
|
+
|
|
100
|
+
result = run_picker(commands, initial_query=args.query)
|
|
101
|
+
if result is None:
|
|
102
|
+
return 1
|
|
103
|
+
|
|
104
|
+
clipboard.copy(result)
|
|
105
|
+
count = result.count("\n") + 1
|
|
106
|
+
plural = "s" if count != 1 else ""
|
|
107
|
+
print(f"shist: copied {count} command{plural} to clipboard", file=sys.stderr)
|
|
108
|
+
return 0
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
if __name__ == "__main__":
|
|
112
|
+
raise SystemExit(main())
|