From 0b5facca6a3c449dcb7335465b11cae169280612 Mon Sep 17 00:00:00 2001 From: Alex Pasmantier <47638216+alexpasmantier@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:13:19 +0100 Subject: [PATCH] feat(shell): add separate history binding for zsh integration (#183) --- crates/television-utils/shell/completion.zsh | 33 +++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/crates/television-utils/shell/completion.zsh b/crates/television-utils/shell/completion.zsh index eeda6f4..3aff40b 100644 --- a/crates/television-utils/shell/completion.zsh +++ b/crates/television-utils/shell/completion.zsh @@ -1,4 +1,4 @@ -_tv_search() { +_tv_smart_autocomplete() { emulate -L zsh zle -I @@ -9,9 +9,9 @@ _tv_search() { output=$(tv --autocomplete-prompt "$current_prompt" $*) - zle reset-prompt if [[ -n $output ]]; then + zle reset-prompt RBUFFER="" LBUFFER=$current_prompt$output @@ -21,9 +21,34 @@ _tv_search() { fi } +_tv_shell_history() { + emulate -L zsh + zle -I -zle -N tv-search _tv_search + local current_prompt + current_prompt=$LBUFFER + + local output + + output=$(tv zsh-history --input "$current_prompt" $*) -bindkey '^T' tv-search + if [[ -n $output ]]; then + zle reset-prompt + RBUFFER="" + LBUFFER=$output + + # uncomment this to automatically accept the line + # (i.e. run the command without having to press enter twice) + # zle accept-line + fi +} + + +zle -N tv-smart-autocomplete _tv_smart_autocomplete +zle -N tv-shell-history _tv_shell_history + + +bindkey '^T' tv-smart-autocomplete +bindkey '^R' tv-shell-history