Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to set the incoming IP address of my SSH client in the tmux status bar but for the life of me I can't figure it out. This is my current setting in my .tmux.conf

set -g status-right '#[fg=white]#(echo $SSH_CONNECTION | awk '{print $1}')'

What gives?

share|improve this question
What about echo $SSH_CLIENT|cut -d " " -f 1? Or to stay with your example: echo $SSH_CONNECTION | awk "{print \$1}" ... – 0xC0000022L May 10 '12 at 13:17
The immediate problem with your status-right is that you are trying to nest single quotes inside other single quotes. STATUS_ACCESS_DENIED's comment and my answer address that issue. – chepner May 10 '12 at 14:26

Try this. Bash parameter expansion allows you to remove a suffix from the expansion of a variable using the % operator. A single % sign matches the shortest suffix, %% the longest. Since SSH_CONNECTION has 3 space-separated fields, you need to use %% to remove all but the first field (the IP address).

${SSH_CONNECTION%% *}  # Remove the first space and everything that follows it.

Since the value of status-right is processed by strftime(3) first, you need to double the percent signs, as strftime will replace %% with a literal %.

set -g status-right '#[fg=white]#(echo ${SSH_CONNECTION%%%% *})'
share|improve this answer
Commands in #() will inherit the “global” environment. This means the value shown will be from when the server was started. If the OP wants the value provided by the most recent client to attach to the session, then they will need to parse the output of tmux show-env. Something like set -g status-right 'foo…#(tmux show-env|grep ^SSH_CONNECTION=|cut -d= -f2|cut -d" " -f1)…bar' (easier to understand?) or set -g status-right 'foo…#(tmux show-env|sed -n "/^SSH_CONNECTION=/{s/[^=]*=//;s/ .*//;p;}")…bar' (fewer processes). – Chris Johnsen May 11 '12 at 3:42
Very good point, and deserving of its own answer. – chepner May 11 '12 at 13:40
Nothing of this work for me :( What it could be? I tried every other example here - empty bar always. – FelikZ Mar 22 at 15:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.