Skip to content

Commit 984ee79

Browse files
committed
Experiment: move PWD and Git info from shell prompt to tmux pane titles
I'm just trying this on for size for now but it looks pretty: https://eseth.org/2019/tmux-status-line.html Pros: - It reduces a bit of CLI clutter and gives a single, stable place to look for certain info. - You can see infos even when running full-screen CLI programs. Cons: - You lose a bit of contextual info when scrolling through the scrollback since you can't see the current directory or current Git hash next to the command you typed. In practice I haven't really missed it so far. - Tmux does not wait for external commands to finish before drawing the UI so in order to view changes in near real-time this requires a fair bit of Zsh machinery to manually tell tmux to refresh after changing directories or running Git commands.
1 parent 7a902eb commit 984ee79

3 files changed

Lines changed: 34 additions & 11 deletions

File tree

.tmux.conf

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,25 @@ set -g message-style "fg=black,bg=green"
101101
setw -g window-status-bell-style "fg=black,bg=green,blink"
102102
setw -g window-status-current-style "fg=blue,bg=white"
103103

104-
# Call out the active pane a bit more.
104+
set -g pane-border-status top
105+
106+
set -g pane-border-style "fg=terminal,bg=terminal"
105107
set -g pane-active-border-style "fg=black,bg=brightblack"
106108

107-
# Only show the pane title if it's a custom title.
108-
# (The default hostname title is just noise.)
109-
set -g pane-border-format "#[fg=black#,bg=brightblack]#{pane_id} #{pane_index}#{?pane_active,*,}#{?#{==:#{host},#{pane_title}},, #{pane_title}}"
109+
# Show pwd, git, and tmux pane info in pane title.
110+
# (Hides the default hostname #{pane_title}.)
111+
set -g pane-border-format "\
112+
#[fg=white,bg=black] \
113+
#(~/bin/git-prompt -c tmux #{pane_current_path} && tmux refresh -S)\
114+
#[align=right,fg=white,bg=black] \
115+
#{pane_id} \
116+
#{pane_index}\
117+
#{?pane_active,*,}\
118+
#{?#{==:#{host},#{pane_title}},, #{pane_title}} \
119+
"
110120

111121
### Status bar.
112122
set -g status-right-length 50
113123
set -g status-right "#[fg=cyan]#h"
114-
set -g pane-border-status bottom
115124

116125
# vim:ft=tmux

.zsh_shouse_prompt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ alias pr_bare="zstyle ':pr_nethack:' mode bare"
2929

3030
# Set default mode when zsh is first loaded (not every time prompt is drawn)
3131
# Modes: full, compact, bare
32-
if [[ $LINES -lt 5 ]] ; then
33-
zstyle ":pr_nethack:" mode bare
34-
else
35-
zstyle ":pr_nethack:" mode compact
36-
fi
32+
zstyle ":pr_nethack:" mode bare
3733
zstyle ':pr_nethack:*' hooks pwd incog usr vcs venv jobs prompt
3834
zstyle ':pr_nethack:*' pet "d" # A domestic animal, the _tame dog_ (_Canis familiaris_)
3935
zstyle ':pr_nethack:*' pwd "%~"

.zshrc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,26 @@ function pman() {
303303

304304
# }}}
305305

306+
function refresh_tmux() {
307+
tmux refresh -S
308+
}
309+
310+
_last_cmd_was_git=0
311+
function last_command_was_git() {
312+
[[ "$1" == git* ]] && _last_cmd_was_git=1
313+
}
314+
315+
function refresh_tmux_on_git() {
316+
if [[ "$_last_cmd_was_git" -eq 1 ]]; then
317+
_last_cmd_was_git=0
318+
tmux refresh -S
319+
fi
320+
}
321+
306322
# Run precmd functions
307-
precmd_functions=( precmd_prompt )
323+
preexec_functions=( last_command_was_git )
324+
chpwd_functions=( refresh_tmux )
325+
precmd_functions=( precmd_prompt refresh_tmux_on_git )
308326

309327
# Allow OS or environment specific overrides:
310328
if [[ -r "$HOME/.zsh_customize" ]]; then

0 commit comments

Comments
 (0)