Last active
May 6, 2025 18:27
-
-
Save dohq/1dc702cc0b46eb62884515ea52330d60 to your computer and use it in GitHub Desktop.
fzf-ssh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fzf-ssh () { | |
local selected_host=$(grep "Host " ~/.ssh/ssh_config | grep -v '*' | cut -b 6- | fzf --query "$LBUFFER" --prompt="SSH Remote > ") | |
if [ -n "$selected_host" ]; then | |
BUFFER="ssh ${selected_host}" | |
zle accept-line | |
fi | |
zle reset-prompt | |
} | |
zle -N fzf-ssh | |
bindkey '^s' fzf-ssh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I also tweaked the grep query a bit, since it was producing some odd results on my .ssh/config. Here's the before and after on the grep.
Here's the BEFORE:
Note that lines 1, 2, and7 are incorrect, and the '*' entry is missing (which is probably a good thing). Line 7 actually comes from a commented out section in my config:
Now here's the AFTER:
Here's my modified version of your zsh function: