Skip to main content

tmux status-bar #(pwd) doesn't reload [Resolved]

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).


Question Credit: conformist
Question Reference
Asked June 17, 2019
Tags: tmux
Posted Under: Unix Linux
45 views
2 Answers

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:


credit: Thomas Dickey
Answered June 17, 2019

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-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.

~/.tmux_path.sh

#!/bin/sh
printf '\033%s\007' $(basename $1) # show full path use $1 instead of $(basename $1)

Make script executable

chmod +x ~/.tmux_path.sh

Example window naming

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

~/.tmux.conf

~ 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})"

credit: DryCola
Answered June 17, 2019
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA