3

I have a problem with the tmux 2.1 status bar. As the manual explains I'd write in ~/.tmux.conf it:

set -g status-right "#(/bin/pwd) %R %d/%m/%g"
set -g status-interval 1

After I start tmux in status bar is /home/conformist. But if I change cwd (like cd /) — status bar is still $HOME.

Everything works perfect if I change conf to:

set -g status-right "#{pane_current_path} %R %d/%m/%g"

I'd like to look in status bar $HOME like ~ and cannot do this, because pwd doesn't change (and pwd | perl -pne s-$HOME-~- doesn't work too).

1

Calling /bin/pwd like that will not work because the program is run by the same process (it is not your shell). If you are using bash, you can modify your prompt to send an escape sequence to tmux to change the window name using the escape sequence shown as an example:

printf '\033kWINDOW_NAME\033\\'

Here is a separate shell script to demonstrate the escape sequence:

#!/bin/sh
printf '\033k%s\033\\' $(pwd)

It is not the same escape sequence used for xterm titles, but you can apply the advice in the Bash Prompt HOWTO in the same way.

Further reading:

|improve this answer|||||
1

Working ENV:

OS

  • OSX 10.14.5

Terminal

Tmux

  • tmux 2.9a

Example status-right field

~/.tmux.config to call out to an external bash script in the example provided, the file is here: ~/.tmux_path.sh

~/.tmux.config

set -g status-interval 1
set -g status-right-length 150
set -g status-right "#(~/.tmux_path.sh #{pane_current_path}) %Y-%m-%d %H:%M:%S"

Example bash script that reads #{pane_current_path) arg. basename truncates the beginning path and just displays current. This is nice if using as a window id. NOTE: This is making an assumption that $HOME = /home/user one might need to adjust -f-1,4- to match the desired outcome.

~/.tmux_path.sh

#!/bin/sh
printf '\033%s\007' $(echo "$1" | awk '{print "~"$1}' | cut -d/ -f-1,4-)

Make script executable

chmod +x ~/.tmux_path.sh

Example window naming

  • Note: Use the same ~/.tmux_path.sh from above

~/.tmux.conf

set -g status-interval 1
set -g window-status-current-format "[#[fg=white] #(~/.tmux_path.sh #{pane_current_path})]"
set -g window-status-format "#[fg=black] #(~/.tmux_path.sh #{pane_current_path})"
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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