Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nesting terminal multiplexers is very good, I do it for exactly the use case you mentioned. Escaping your escape key is easy, with a little practice you won't even realize you're doing it.

I have a shell function called 'go' that creates a new screen and labels it, connects to the remote host via SSH, and then recreates or re-attaches to the remote scren as appropriate. My top level screen session currently has 8 remote hosts I'm logged into, each running their own nested screen sessions.

My go() function also reads my ~/.ssh/config file to grab all my host aliases so I can tab complete to them. Note, I'm a Perl programmer, and rarely write shell scripts, so this function may be kinda ugly.

    go()
    {
        local OPTIND OPTARG
        local SCREENCMD="screen -dRR"

        while getopts "xn" flag; do
            case "$flag" in
                x) SCREENCMD="screen -xRR"; shift;;
                n) SCREENCMD=""; shift;;
            esac
        done

        if [ "$#" == "0" ]; then
            echo "Need someplace to go."
            return 1;
        fi

        while (( "$#" )); do
            screen -t $1 ssh -tq $1 $SCREENCMD
            shift
        done
    }

    _go_show()
    {
        local curr opts
        cur="${COMP_WORDS[COMP_CWORD]}"
        opts=$(grep 'Host ' ~/.ssh/config | cut -d' ' -f2)
        COMPREPLY=( $(compgen -W "${opts}" ${cur}) )
    }
    complete -F _go_show go


You should know that the bash-completion package in Debian and kin does tab-expansion of ssh hosts in known_hosts and config. Also handles the --argument switches for just about all common utilities.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: