mirror of
https://github.com/prdlk/dotfiles.git
synced 2026-11-02 11:32:42 +00:00
25 lines
912 B
Bash
Executable File
25 lines
912 B
Bash
Executable File
#!/bin/bash
|
|
# ~/.config/tmux/tab-label.sh — the non-editor tab label, kitty tab_bar.py's
|
|
# rule: the repo the pane's cwd belongs to (dir name if no repo, ~ at home).
|
|
# Editors (the open file) are handled in tmux.conf's automatic-rename-format.
|
|
# Args: $1 pane_current_path $2 window_id
|
|
|
|
path=$1 window=$2
|
|
|
|
if [[ $path == "$HOME" ]]; then
|
|
label='~'
|
|
else
|
|
dir=$path
|
|
while [[ -n $dir && ! -e $dir/.git ]]; do dir=${dir%/*}; done
|
|
root=${dir:-$path}
|
|
label=${root##*/}
|
|
fi
|
|
printf '%s' "$label"
|
|
|
|
# tmux runs #() jobs async and only re-checks a window's name on pane output,
|
|
# so after a `cd` the tab would keep the old label until the next keystroke.
|
|
# Re-arming automatic-rename makes tmux re-check now and pick up this output.
|
|
if [[ -n $window && $(tmux display -p -t "$window" '#W' 2>/dev/null) != *"${label:0:26}"* ]]; then
|
|
tmux set -w -t "$window" automatic-rename on >/dev/null 2>&1 &
|
|
fi
|