Skip to content

Instantly share code, notes, and snippets.

@m42e
Forked from dohq/fzf-ssh.zsh
Last active June 2, 2019 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m42e/193970126d0aa2429283560954155ca5 to your computer and use it in GitHub Desktop.
Save m42e/193970126d0aa2429283560954155ca5 to your computer and use it in GitHub Desktop.
fzf-ssh
function _resolv_ssh_hosts () {
local CURRENTFILE
eval CURRENTFILE=$1
local selectedhosts=$(grep "Host " ${CURRENTFILE} | grep -v '*' | cut -b 6-)
local includes=$(grep "Include " ${CURRENTFILE} | cut -b 9-)
for inc in ${(@f)includes}; do
selectedhosts+=$(_resolv_ssh_hosts $inc)
done
echo $selectedhosts
}
function fzf-ssh () {
local selected_host=$(_resolv_ssh_hosts ~/.ssh/config | $(__fzfcmd) --query "$LBUFFER")
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