Otherwise, I'd be running tmux on my local machine, then want to run tmux on a remote machine, and nesting terminal multiplexers is not good.
Otherwise, I'd be running tmux on my local machine, then want to run tmux on a remote machine, and nesting terminal multiplexers is not good.
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 goIt kind of sucks if you accidentally use a hardstatusline in both the nesting and the nested muxes, and it slightly sucks if you use the same escape key for both/all levels of nesting.
I have been using a nested screen setup for ~3 years at home and it's great. My outer screen uses ^Z as its escape key (I ^Z very few commands) and the inner ones use ^O.
It works wonderfully, and I never have a problem remembering which screen has what because of the different escape keys. It's sort of like the finger memory that you develop if you use multiple workspaces (esp in a WM that supports tagging windows) and always keep the same things on the same workspaces.
also, using ^a^a to send commands to the nested tmux isn't so bad.. but to get to the third one down you need to use ^a^a^a^a as you need to send a ^a^a to the second one in..
for the fourth nest you need 8 ^a's, but again, it's a bit like code indentation, if you're 4 tmuxes deep, then there's a good chance you're doing it wrong
but still, it's nice to be able to do it if necessary