Last active
November 9, 2016 08:08
-
-
Save yousan/6a1339f76475cec77df6fd905bc2a695 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# @see http://qiita.com/miya0001/items/4dc5949dd792963ef578 Thanks! | |
# Usage: ssh [email protected] | |
# Automatically adds `-i [email protected]` argument for `ssh` command. | |
# test: bash -c 'source ssh_bash.bash; ssh [email protected] ls' | |
function ssh { | |
local HOSTSTR | |
SSH=`which ssh` | |
for i in "$@" | |
do | |
case $i in | |
-*) # this is option | |
# echo "this is option" "${i#*=}" | |
;; | |
#echo "${i#*=}" | |
# the first non-hyphoned argument must be a hostname (honto? | |
# $ ssh -h | |
# ssh: illegal option -- h | |
# usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] | |
# [-D [bind_address:]port] [-E log_file] [-e escape_char] | |
# [-F configfile] [-I pkcs11] [-i identity_file] [-L address] | |
# [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] | |
# [-Q query_option] [-R address] [-S ctl_path] [-W host:port] | |
# [-w local_tun[:remote_tun]] [user@]hostname [command] | |
*) | |
if [ -z "$HOSTSTR" ]; then | |
HOSTSTR="${i#*=}" | |
fi | |
;; | |
esac | |
done | |
if [ -f ~/.ssh/"${HOSTSTR}" ]; then | |
$SSH -i ~/.ssh/${HOSTSTR} $@ | |
else | |
$SSH $@ | |
fi | |
# if [ -f ./.ssh-config ]; then | |
# /usr/bin/ssh -F ./.ssh-config $@ | |
# else | |
# /usr/bin/ssh $@ | |
# fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment