2026-08-14 13:53:55 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""atuin-pick: atuin history picker for a kitty split (ctrl+shift+p).
|
|
|
|
|
|
|
|
|
|
atuin search -i draws its TUI on the tty and prints the selected command
|
|
|
|
|
to stdout (Esc prints nothing). Filter to history from the current
|
2026-08-14 14:03:50 -04:00
|
|
|
directory. Hand the selection to an interactive fish via --init-command:
|
|
|
|
|
it runs inside that shell (aliases/abbr resolve, cd persists) with its
|
|
|
|
|
output in the split, and the prompt drops down below it.
|
2026-08-14 13:53:55 -04:00
|
|
|
"""
|
|
|
|
|
import os
|
2026-08-14 14:03:50 -04:00
|
|
|
import shlex
|
2026-08-14 13:58:17 -04:00
|
|
|
import shutil
|
2026-08-14 13:53:55 -04:00
|
|
|
import subprocess
|
|
|
|
|
|
2026-08-14 13:58:17 -04:00
|
|
|
# kitty's launch env has neither ~/.atuin/bin on PATH nor ATUIN_SESSION
|
|
|
|
|
# (atuin's shell init never ran), so resolve and seed both here.
|
|
|
|
|
atuin = shutil.which("atuin") or os.path.expanduser("~/.atuin/bin/atuin")
|
2026-08-14 13:53:55 -04:00
|
|
|
if "ATUIN_SESSION" not in os.environ:
|
|
|
|
|
os.environ["ATUIN_SESSION"] = subprocess.run(
|
2026-08-14 13:58:17 -04:00
|
|
|
[atuin, "uuid"], stdout=subprocess.PIPE, text=True
|
2026-08-14 13:53:55 -04:00
|
|
|
).stdout.strip()
|
|
|
|
|
|
|
|
|
|
sel = subprocess.run(
|
2026-08-14 13:58:17 -04:00
|
|
|
[atuin, "search", "-i", "--filter-mode", "directory"],
|
2026-08-14 13:53:55 -04:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
|
text=True,
|
|
|
|
|
).stdout.strip()
|
2026-08-14 14:03:50 -04:00
|
|
|
|
|
|
|
|
argv = ["fish"]
|
2026-08-14 13:53:55 -04:00
|
|
|
if sel:
|
2026-08-14 14:03:50 -04:00
|
|
|
argv += ["-C", f"echo {shlex.quote('\u276f ' + sel)}; {sel}"]
|
|
|
|
|
os.execvp("fish", argv)
|