Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Tmux pane PWD at the prompt</h2> <p>There are several ways that you can do this. I do it myself. The easiest and most customisable way is to set a global variable that tmux can access.</p> <p>First add this to your <code>.bashrc</code> or <code>.zshrc</code> file, to set the PWD variable after every prompt:</p> <pre><code># create a global per-pane variable that holds the pane's PWD export PS1=$PS1'$( [ -n $TMUX ] &amp;&amp; tmux setenv -g TMUX_PWD_$(tmux display -p "#D" | tr -d %) $PWD)' </code></pre> <p>Now, make a script that displays this variable such as <code>~/bin/display_tmux_pane_pwd.sh</code>:</p> <pre><code>#!/bin/bash tmux showenv -g TMUX_PWD_$(tmux display -p "#D" | tr -d %) | sed 's/^.*=//' </code></pre> <p>All that is left is to add this to the satis-bar in <code>.tmux.conf</code>:</p> <pre><code>set -g status-left '#(~/bin/display_tmux_pane_pwd.sh)' </code></pre> <p>It may take awhile to update after switching panes, so you can change that with this command. By default it updates every 15 seconds, this will make it 5 seconds. Change it as you like.</p> <pre><code>set -g status-interval 5 </code></pre> <hr> <h2>Tmux-pane PWD in other programs</h2> <p>Sometimes it is useful to open up a pane or window and immediately execute a program instead of booting up another shell (e.g. <code>tmux new-window vim</code>). This way, when you close that program you also close the window. Unfortunately, the way I describe above requires a prompt in order to broadcast the status of PWD. However, in many programs, you can work around this fairly easily. Here's an example of what is in my <code>.vimrc</code> file so that vim updates the PWD status whenever it changes buffers.</p> <pre><code>if exists("$TMUX") " Get the environment variable let tmux_pane_name_cmd = 'tmux display -p \#D' let tmux_pane_name = substitute(system(g:tmux_pane_name_cmd), "\n", "", "") let tmux_env_var = "TMUX_PWD_" . substitute(g:tmux_pane_name, "%", "", "") unlet tmux_pane_name tmux_pane_name_cmd function! BroadcastTmuxCwd() let filename = substitute(expand("%:p:h"), $HOME, "~", "") let output = system("tmux setenv -g ".g:tmux_env_var." ".l:filename) endfunction autocmd BufEnter * call BroadcastTmuxCwd() endif </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload