From 13ecc0fef880c1e4a13dd444b2ef3de7c1b00656 Mon Sep 17 00:00:00 2001 From: Jer Noble Date: Thu, 26 Apr 2012 08:57:52 -0700 Subject: [PATCH 1/1] Add ssh-helper functions. --- .aliases | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/.aliases b/.aliases index 163f842..77c68f0 100755 --- a/.aliases +++ b/.aliases @@ -64,3 +64,35 @@ function ssh-learn() { ssh-keyscan -t rsa $1 >> ~/.ssh/known_hosts } +function _ssh_complete() { + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + opts=$( grep -o '^[^, ]\+' ~/.ssh/known_hosts ) + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 +} +complete -F _ssh_complete ssh + +function _ssh_screen () { + DISCONNECT="" + RECONNECT="-R" + HOST=$1 + while [ "$2" != "" ]; do + case $2 in + -d | --disconnect ) + DISCONNECT="-D" + ;; + * ) + echo "Usage: $HOST [-d | --discconnect]" + return 1 + ;; + esac + shift + done + + ssh -t $HOST screen $DISCONNECT $RECONNECT +} + +for host in ssh_hosts=$( grep '^Host[ ][^*]' ~/.ssh/config | cut -c 6- ); do + alias "$host"="_ssh_screen $host $@" +done -- 2.40.1