I am trying to display my ipaddress and the date on the right side of my tmux status line. I have the following command:
set -g status-right "#[fg-cyan]#(ifconfig | awk '$1 == "inet" { print $2 }') #[fg=cyan]%d %b %R"
It is displaying the date but not the ipaddress. I am not getting any error from Tmux so I am not sure what is going wrong.
Any help is apprecited!
Check the value that actually ends up being set:
tmux show-option -g | grep status-right
I expect that you will find that there are no double quotes around inet
. The double quote parsing does not consider the #()
syntax as special (unlike "$()"
in shells, where you can simply use double quotes inside the command substitution). Thus, the parsing is done in three pieces:
"#[fg-cyan]#(ifconfig | awk '$1 == "
inet
" { print $2 }') #[fg=cyan]%d %b %R"
These are concatenated into this:
#[fg-cyan]#(ifconfig | awk '$1 == inet { print $2 }') #[fg=cyan]%d %b %R
As an awk program, this ends up checking $1
against an unset variable named inet
instead of the literal string "inet"
; awk will probably not complain, but no lines will ever match.
You can escape the double quotes to let them pass into the final string:
set -g status-right "#[fg-cyan]#(ifconfig | awk '$1 == \"inet\" { print $2 }') #[fg=cyan]%d %b %R"
When I set this, I just see 127.0.0.1
though; you might want to add a |tail -1
to use the last line instead of the first.
Two other items:
[fg-
instead of [fg=
, andThus:
set -g status-right "#[fg=cyan]#(ifconfig | awk '$1 == \"inet\" { print $2 }'|tail -1) %d %b %R"