Last active
August 29, 2015 14:11
-
-
Save zzl0/5c97a432eaaaa92a0824 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 | |
#--------------------- start ---------------------- | |
# Copy the flowwing to your .zshrc file. | |
# # COMPLETION SETTINGS | |
# # add custom completion scripts | |
# fpath=(~/.zsh/completion $fpath) | |
# # compsys initialization | |
# autoload -U compinit | |
# compinit | |
# # show completion menu when number of options is at least 2 | |
# zstyle ':completion:*' menu select=2 | |
#---------------------- end ----------------------- | |
if [ -z "$1" ] | |
then | |
echo -e "\nLogin to multi host easily.\n" | |
echo -e "Usage: $(basename $0) <host>\n" | |
exit 1 | |
fi | |
# Set the follwing two variables | |
USER=xxx | |
ROOT_DIR=~/.zsh/completion/ | |
HOSTNAME_FILE=${ROOT_DIR}/hostnames | |
COMPLETE_FILE=${ROOT_DIR}/_sshgo | |
TMP_FILE=${ROOT_DIR}/.tmp | |
host=$1 | |
# Add to hostnames file if host not exist | |
# and generate new complete file | |
if [ ! -f ${HOSTNAME_FILE} ] | |
then | |
touch ${HOSTNAME_FILE} | |
fi | |
if ! grep -Fxq ${host} ${HOSTNAME_FILE} | |
then | |
echo ${host} >> ${HOSTNAME_FILE} | |
echo "#compdef sshgo" > ${TMP_FILE} | |
echo "" >> ${TMP_FILE} | |
hostnames=`cat ${HOSTNAME_FILE} | paste -sd " " -` | |
echo "_arguments \"1: :(${hostnames})\"" >> ${TMP_FILE} | |
mv ${TMP_FILE} ${COMPLETE_FILE} | |
fi | |
# ssh to host | |
ssh "${USER}@${host}" |
Author
zzl0
commented
Dec 13, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment