8000 feat(shell): support completion in the middle of a prompt by dkmar · Pull Request #450 · alexpasmantier/television · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(shell): support completion in the middle of a prompt #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions television/utils/shell/completion.bash
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
function tv_smart_autocomplete() {
# prefix (lhs of cursor)
local current_prompt="${READLINE_LINE:0:$READLINE_POINT}"

local output=$(tv --autocomplete-prompt "$current_prompt")
local output=$(tv --autocomplete-prompt "$current_prompt" | tr '\n' ' ')

if [[ -n $output ]]; then
# suffix (rhs of cursor)
local rhs="${READLINE_LINE:$READLINE_POINT}"
# add a space if the prompt does not end with one
[[ "${current_prompt}" != *" " ]] && current_prompt="${current_prompt} "

READLINE_LINE=$current_prompt$output
READLINE_POINT=${#READLINE_LINE}
local lhs=$current_prompt$output
READLINE_LINE=$lhs$rhs
READLINE_POINT=${#lhs}
fi
}

Expand Down
8000
5 changes: 3 additions & 2 deletions television/utils/shell/completion.fish
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
function tv_smart_autocomplete
# prefix (lhs of cursor)
set -l current_prompt (commandline -cp)

set -l output (tv --autocomplete-prompt "$current_prompt")

if test -n "$output"
# add a space if the prompt does not end with one (unless the prompt is an implicit cd, e.g. '\.')
string match -q -r '.*( |./)$' -- "$current_prompt" || set current_prompt "$current_prompt "
commandline -r "$current_prompt$output"
string match -q -r '.*( |./)$' -- "$current_prompt" || set output " $output"
commandline -i "$output"
commandline -f repaint
end
end
Expand Down
18 changes: 10 additions & 8 deletions television/utils/shell/completion.zsh
C70E
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ _tv_smart_autocomplete() {
emulate -L zsh
zle -I

# prefix (lhs of cursor)
local current_prompt
current_prompt=$LBUFFER

local output

output=$(tv --autocomplete-prompt "$current_prompt" $*)

output=$(tv --autocomplete-prompt "$current_prompt" $* | tr '\n' ' ')

if [[ -n $output ]]; then
zle reset-prompt
RBUFFER=""
# suffix (rhs of cursor)
local rhs=$RBUFFER
# add a space if the prompt does not end with one
[[ "${current_prompt}" != *" " ]] && current_prompt="${current_prompt} "

LBUFFER=$current_prompt$output
CURSOR=${#LBUFFER}
RBUFFER=$rhs

# uncomment this to automatically accept the line
zle reset-prompt
# uncomment this to automatically accept the line
# (i.e. run the command without having to press enter twice)
# zle accept-line
fi
Expand All @@ -39,7 +42,7 @@ _tv_shell_history() {
RBUFFER=""
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)
# zle accept-line
fi
Expand All @@ -52,4 +55,3 @@ zle -N tv-shell-history _tv_shell_history

bindkey '{tv_smart_autocomplete_keybinding}' tv-smart-autocomplete
bindkey '{tv_shell_history_keybinding}' tv-shell-history

0