Skip to content

Commit

Permalink
Add xonsh ctrl-R search
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu-LAURENT39 committed Nov 9, 2023
1 parent bdca792 commit a084eaf
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion atuin/src/shell/atuin.xsh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,24 @@ def _atuin_postcommand(cmd: str, rtn: int, out, ts):
# For more details, see https://github.com/xonsh/xonsh/issues/5224
# (atuin history end --exit @(rtn) -- $ATUIN_HISTORY_ID &) > /dev/null 2>&1
atuin history end --exit @(rtn) -- $ATUIN_HISTORY_ID > /dev/null 2>&1
del $ATUIN_HISTORY_ID
del $ATUIN_HISTORY_ID

import tempfile
from prompt_toolkit.keys import Keys
@events.on_ptk_create
def _custom_keybindings(bindings, **kw):

@bindings.add(Keys.ControlR)
def search(event):
# We can't use $() notation, as that would prevent the TUI from being shown
# xonsh.lib.subprocess.check_output has the same issue, and
# xonsh.lib.subprocess.run can't capture output.
# xonsh.procs.specs.SubprocSpec doesn't support redirecting output either.
# As inefficient as it is, we have to use a temporary file
with tempfile.NamedTemporaryFile(mode="w+", encoding="utf8") as f:
atuin search -i -- @(event.current_buffer.text) e> @(f.name)
cmd = f.read().rstrip('\n')
event.current_buffer.reset()
event.current_buffer.insert_text(cmd)

del _custom_keybindings

0 comments on commit a084eaf

Please sign in to comment.