powerline
powerline copied to clipboard
tmux hostname segment and ssh.
If I have the "only_if_ssh"=true
option set for the hostname segment in the default tmux configuration, then I expect to see the hostname only if I am using ssh. This is work as expected provided that there is no other tmux session running on the host. If I have a session already running, then the hostname does not show.
Steps:
- Log into your machine via the console.
- Starts tmux: hostnane does not show, as expected.
- Log into your machine via ssh.
- Start tmux: hostname does not show whereas was expecting it to show.
Bug? Or am I doing something weird.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Currently it is basing ssh detection on presence of SSH_CLIENT environment variable. But environment variables are read from tmux server, so they are identical for all of the tmux sessions and are inherited from the environment where tmux server starts (which is the environment where you first create tmux session).
I will see what is the best way to handle this situation.
For the reason ZyX-I mentioned, it seems like it might be almost impossible to set this value properly. Even if you could detect things about the shell that is currently attached to the tmux session, consider, for example, that you could attach to the same session locally and remotely at the same time. Its not even really clear what the behavior should be in that case.
SSH_CLIENT
got deprecated in favor of SSH_CONNECTION
. The latter is available even within tmux, IMHO a small change from
https://github.com/powerline/powerline/blob/8b07f6396127f50fb73de9020912ae252d3ed170/powerline/segments/common/net.py#L30
to
if only_if_ssh and not segment_info['environ'].get('SSH_CONNECTION'):
might solve the problem.