Skip to content

Instantly share code, notes, and snippets.

@hitsumabushi
Last active July 10, 2017 07:59
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 hitsumabushi/5ef85d9ba8afdb667aaf2e9f13dcb0d1 to your computer and use it in GitHub Desktop.
Save hitsumabushi/5ef85d9ba8afdb667aaf2e9f13dcb0d1 to your computer and use it in GitHub Desktop.
peco + usacloud for ssh
##
# select ssh host from usacloud server list
#
function peco-select-usacloud-ssh-host(){
local res
# IPでアクセス
res=$(echo $row | cut -d'|' -f 6 | sed -e 's/ *\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)\/.*/\1/')
# hostname が名前解決できる場合
# row=$(usacloud server list | grep -v "^\+--" | peco)
res=$(echo $row | awk '{print $4;}')
if zle; then
if [ -n "$res" ]; then
BUFFER="ssh $res"
zle accept-line
fi
CURSOR=$#BUFFER
zle clear-screen
else
if [ -n "$res" ]; then
BUFFER="ssh $res"
print -z "${BUFFER}"
fi
fi
}
zle -N peco-select-usacloud-ssh-host
bindkey '^g' peco-select-usacloud-ssh-host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment