mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-07 12:05:34 +00:00
feat(shell): zsh support completion in the middle of a prompt
This commit is contained in:
parent
251d2e6f5f
commit
000d18b32e
@ -6,18 +6,19 @@ _tv_smart_autocomplete() {
|
|||||||
current_prompt=$LBUFFER
|
current_prompt=$LBUFFER
|
||||||
|
|
||||||
local output
|
local output
|
||||||
|
output=$(tv --autocomplete-prompt "$current_prompt" $* | tr '\n' ' ')
|
||||||
output=$(tv --autocomplete-prompt "$current_prompt" $*)
|
|
||||||
|
|
||||||
|
|
||||||
if [[ -n $output ]]; then
|
if [[ -n $output ]]; then
|
||||||
zle reset-prompt
|
local rhs=$RBUFFER
|
||||||
RBUFFER=""
|
|
||||||
# add a space if the prompt does not end with one
|
# add a space if the prompt does not end with one
|
||||||
[[ "${current_prompt}" != *" " ]] && current_prompt="${current_prompt} "
|
[[ "${current_prompt}" != *" " ]] && current_prompt="${current_prompt} "
|
||||||
LBUFFER=$current_prompt$output
|
|
||||||
|
|
||||||
# uncomment this to automatically accept the line
|
LBUFFER=$current_prompt$output
|
||||||
|
CURSOR=${#LBUFFER}
|
||||||
|
RBUFFER=$rhs
|
||||||
|
|
||||||
|
zle reset-prompt
|
||||||
|
# uncomment this to automatically accept the line
|
||||||
# (i.e. run the command without having to press enter twice)
|
# (i.e. run the command without having to press enter twice)
|
||||||
# zle accept-line
|
# zle accept-line
|
||||||
fi
|
fi
|
||||||
@ -39,7 +40,7 @@ _tv_shell_history() {
|
|||||||
RBUFFER=""
|
RBUFFER=""
|
||||||
LBUFFER=$output
|
LBUFFER=$output
|
||||||
|
|
||||||
# uncomment this to automatically accept the line
|
# uncomment this to automatically accept the line
|
||||||
# (i.e. run the command without having to press enter twice)
|
# (i.e. run the command without having to press enter twice)
|
||||||
# zle accept-line
|
# zle accept-line
|
||||||
fi
|
fi
|
||||||
@ -52,4 +53,3 @@ zle -N tv-shell-history _tv_shell_history
|
|||||||
|
|
||||||
bindkey '{tv_smart_autocomplete_keybinding}' tv-smart-autocomplete
|
bindkey '{tv_smart_autocomplete_keybinding}' tv-smart-autocomplete
|
||||||
bindkey '{tv_shell_history_keybinding}' tv-shell-history
|
bindkey '{tv_shell_history_keybinding}' tv-shell-history
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user