Is there any way to detect how many levels of tmux I'm currently in? I've been able to hack it with 2 levels by simply checking [[ -n $SSH_CLIENT && -n $TMUX ]], so I can have one level on the client and one on the server. I use that check to setup a different prefix (ctrl-a, ctrl-b).But now I'm finding I want to ssh from inside the server shell, so would like even a third level, thus requiring a third prefix combination to be setup.
How to detect TMux level
tmux
Apparently there is no way to check what tmux depth you are currently on. However you can easily bake your own solution. Just make a variable in your .bashrc/.bash_profile/.profile like so:if [[ ! -n ${LC_NESTING_DEPTH} ]]; then    export LC_NESTING_DEPTH=1else    export LC_NESTING_DEPTH=$(expr 1 + $LC_NESTING_DEPTH)fiSince the .bashrc gets loaded every time you enter tmux, the variable gets incremented two. You can even pass the variable over ssh by adding SendEnv LC_NESTING_DEPTH to the ~/.ssh/config on your machine, and AcceptEnv LC_NESTING_DEPTH in the /etc/ssh/sshd_config on the machine you're ssh-ing to (See man ssh_config and man sshd_config for more info on that). I couldn't test ssh-ing from a running ssh session, but I assume you can pass the variable on from there as well.