Skip to content
Merged
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
23 changes: 19 additions & 4 deletions zsh-ssh.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ _set_lbuffer() {
}

fzf_complete_ssh() {
local tokens cmd result selected_host
local tokens cmd result key selection
setopt localoptions noshwordsplit noksh_arrays noposixbuiltins

tokens=(${(z)LBUFFER})
Expand Down Expand Up @@ -235,12 +235,27 @@ fzf_complete_ssh() {
--no-separator \
--bind 'shift-tab:up,tab:down,bspace:backward-delete-char/eof' \
--preview 'ssh -T -G $(cut -f 1 -d " " <<< {}) | grep -i -E "^User |^HostName |^Port |^ControlMaster |^ForwardAgent |^LocalForward |^IdentityFile |^RemoteForward |^ProxyCommand |^ProxyJump " | column -t' \
--preview-window=right:40%
--preview-window=right:40% \
--expect=alt-enter,enter
)

if [ -n "$result" ]; then
_set_lbuffer $result true
zle accept-line
key=${result%%$'\n'*}
if [[ "$key" == "$result" ]]; then
selection="$result"
key=""
else
selection=${result#*$'\n'}
fi
Comment on lines +244 to +249

Copilot AI Aug 30, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This logic for parsing the fzf result with expect keys is complex and could benefit from a comment explaining the format. When --expect is used, fzf returns the key on the first line and the selection on subsequent lines, but this isn't immediately clear from the code.

Copilot uses AI. Check for mistakes.

if [ -n "$selection" ]; then
_set_lbuffer "$selection" true
if [[ "$key" == "alt-enter" ]]; then
zle reset-prompt
else
zle accept-line
fi
fi
fi

zle reset-prompt

Copilot AI Aug 30, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zle reset-prompt call at line 261 is now redundant since it's already called at line 254 when alt-enter is pressed. This could lead to unnecessary prompt resets in the alt-enter case.

Suggested change
zle reset-prompt
# Only reset prompt if not already done for alt-enter
if [[ "$key" != "alt-enter" ]]; then
zle reset-prompt
fi

Copilot uses AI. Check for mistakes.
Expand Down