-
-
Save m42e/193970126d0aa2429283560954155ca5 to your computer and use it in GitHub Desktop.
fzf-ssh
This file contains 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 _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