I am trying to figure out a way to detect whether the current terminal/connection (and under a tmux session as well) is through mosh or not.
From this thread, I found which pseudo-terminal session I am currently on:
$ tty
/dev/pts/69
So, I need to some information of the process that spawned this pseudo-terminal, or owns this tty as a children. With the information, perhaps I might be able to determine whether it is from sshd or mosh. But how can I do that?
Another challenge: If the current shell is under tmux, the retrieved tty might not match the sshd/mosh-server information since tmux also allocates another pseudo-terminal. Regardless of how the tmux session was created, I'll need to distinguish my current connection is from SSH or mosh. How will it be possible?
Some trials:
(1) For SSH, it was possible to find the sshd process that matches the tty:
$ ps x | grep sshd | grep 'pts\/27'
5270 ? S 0:00 sshd: wookayin@pts/27
So I can know the current connection is through SSH. However, through mosh, I could not find any relevant information.
(2) Using environment variables like SSH_CLIENT or SSH_TTY might not work because both ssh/mosh set these variables, and it is even wrong inside a tmux session.