Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tmux: How to configure tmux to display the current working directory of a pane on the status bar?

Tags:

I am new to tmux and I am trying to edit my tmux.conf file to have the left side of the status bar reflect:

[SessionName] [CurrentPane] [CurrentWorkingDirectory]

I am able to display the SessionName and CurrentPane. However I can't get to display the CurrentWorkingDirectory.

I've tried several #(shell command) options:

  1. #(tmux select-pane -t :.#P; pwd) : But this prints some other $PWD variable which does NOT reflect the current directory of the bash session in the current pane.

  2. #(tmux select-pane -t :.#P; tmux send-keys pwd Enter) Firstly, although it did print the CurrentWorkingDirectory if I'm in a terminal. It prints this in the terminal and NOT in the status bar like how I want it. Secondly, It entered "pwd Enter" every 15 seconds whether or not I was in a terminal, which was a hassle to reverse if your not as quick (like I am).

I've tried these options but to no avail, is it possible to do what I want? and how?

like image 672
rajames Avatar asked May 18 '13 13:05

rajames


People also ask

How do I change the tmux pane?

Tmux uses the keybinding 'Prefix' followed by 'Ctrl+o' to cycle around the panes. When you use this key-binding for the first time, it moves the pane in one position clockwise.

How do I navigate between tmux Windows?

Switching between panes To get from one pane to another, press Ctrl+B followed by O (as in other).

How do I change the color of my tmux?

How to toggle between light-background and dark-background themes in tmux. Now Ctrl + b Shift + t toggles between light and dark mode. You might want to add more lines to the script to change other options like pane-border-style and pane-active-border-style (the colours of the pane borders) between light and dark mode.


2 Answers

There is a variable for that, which doesn't seem to be in the manpage but is mentioned in the development version. For me, it works in the 1.8 release of tmux.

set -g status-left "#{pane_current_path}"

Note that it also works when you put it in the window-status. Each window status will mention respective working directories.

setw -g window-status-format "#{pane_current_path}".
like image 94
gospes Avatar answered Sep 18 '22 09:09

gospes


I'm not sure how to do this in bash, but in zsh, there's a hook that gets run before every command. In your .zshrc:

precmd () {
    tmux set -qg status-left "#S #P $(pwd)"
}

This will run that tmux command everytime you run a command. Hope this helps. Since bash doesn't have a precmd, I'm not sure how to do this.

like image 34
Chris W. Avatar answered Sep 20 '22 09:09

Chris W.