Last active
March 3, 2019 11:22
-
-
Save tsuyoshicho/da2cb89a93fe001fd344c80475260ce8 to your computer and use it in GitHub Desktop.
sshのconfigからpeco/fzfでssh login(n番煎じ) ref: https://qiita.com/tsuyoshi_cho/items/0dc8973d4becf6f2d784
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
@echo off | |
sh %~dp0ssh-select.sh %* |
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
#!/bin/sh | |
host="" | |
# need backslash escape? ... currently not use backslash | |
if which fzf >/dev/null 2>&1; then | |
host=$(grep -iEh "^host[[:space:]]" ~/.ssh/config ~/.ssh/conf.d/*.conf | sed -e 's/host[[:space:]]\(.*\)/\1/i' | tr ' ' '\n' | grep -v -e '[*?]' -e '^[[:space:]]*$' | fzf --prompt="Host\\> " --query="${*}" --select-1 | xargs -n 1) | |
# use OPT env --ansi --reverse | |
elif which peco >/dev/null 2>&1; then | |
host=$(grep -iEh "^host[[:space:]]" ~/.ssh/config ~/.ssh/conf.d/*.conf | sed -e 's/host[[:space:]]\(.*\)/\1/i' | tr ' ' '\n' | grep -v -e '[*?]' -e '^[[:space:]]*$' | peco --prompt="Host\\> " --query="${*}" --select-1 | xargs -n 1) | |
else | |
echo "selector not found" | |
fi | |
if [ ! -z "$host" ]; then | |
echo "Connect " "$host" | |
ssh "$host" | |
fi | |
# EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment