[zsh,tmux] Set the tmux window name from the ZSH prompt

This commit is contained in:
Eryn Wells 2022-05-22 17:03:00 -07:00
parent d5ede2e563
commit 98dd139677
2 changed files with 47 additions and 25 deletions

View file

@ -15,6 +15,7 @@ set -g visual-bell off
# Pass xterm titles through
set -g set-titles on
set -g set-titles-string "#T"
set -g allow-rename on
# Use vi keys for copy mode
set -g mode-keys vi
@ -30,26 +31,30 @@ set -g status-left-style bg=green,fg=black
set -g status-right "#[bg=red,fg=white] #h #[bg=blue,fg=white] %H:%M %Y-%m-%d #[default]"
# Start window and pane indexing from 1 instead of 0
set-option -g base-index 1
set-option -g pane-base-index 1
set -g base-index 1
set -g pane-base-index 1
# Tabs like this: "(<index>:<window_name>)"
setw -g window-status-style "fg=white,bg=black"
setw -g window-status-format " #I #W "
setw -g window-status-current-style "fg=white,bg=blue"
setw -g window-status-current-format " #I #W "
setw -g window-status-separator ""
set -g window-status-style "fg=white,bg=black"
set -g window-status-format " #I #W "
set -g window-status-current-style "fg=white,bg=blue"
set -g window-status-current-format " #I #W "
set -g window-status-separator ""
setw -g window-status-bell-style "bg=red"
setw -g window-status-activity-style "bg=red"
set -g window-status-bell-style "bg=red"
set -g window-status-activity-style "bg=red"
setw -g alternate-screen on
set -g alternate-screen on
setw -g clock-mode-style 24
set -g clock-mode-style 24
# Lock the screen after 120 seconds
set-option -g lock-after-time 0
set-option -g lock-command "tmux clock-mode"
set -g lock-after-time 0
set -g lock-command "tmux clock-mode"
#
# KEY BINDINGS
#
bind-key C-a last-window
# TODO: Decide if this should have a -n (allow invoking the command without the leader).

View file

@ -27,10 +27,12 @@ function prompt_loquacious_setup
add-zsh-hook chpwd set_repo_name
add-zsh-hook precmd set_xterm_title
add-zsh-hook precmd set_tmux_window_name
add-zsh-hook precmd print_newline
add-zsh-hook precmd set_prompt_info
add-zsh-hook preexec print_newline
add-zsh-hook preexec set_tmux_window_name
prompt_opts=(cr subst percent)
@ -80,13 +82,13 @@ function set_repo_name
function set_prompt_info
{
PS1_HISTORY="`prompt_colorize -b -f 'green' '%h'`"
PS1_NAME="`prompt_colorize -f 'magenta' '%n'` "
PS1_CWD="in `prompt_colorize -f 'green' '%~'` "
PS1_STATUS="%(?..`prompt_colorize -b -f 'red' '!'`) "
PS1_HISTORY="%F{green}%H%f"
PS1_NAME="%F{magenta}%n%f "
PS1_CWD="in %F{green}%~%f "
PS1_STATUS="%(?..%F{red}!%f) "
if [[ -n "$SSH_CONNECTION" ]]; then
PS1_HOST="at `prompt_colorize -f 'red' '%m'` "
if [[ -n "$SSH_CONNECTION" && "$TERM_PROGRAM" -ne "tmux" ]]; then
PS1_HOST="at %F{red}%m%f "
else
PS1_HOST=''
fi
@ -106,22 +108,23 @@ function set_prompt_info
fi
# Show background job count if any exist.
RPS1="%(1j.[`prompt_colorize -f 'magenta' '%j'`].)"
RPS1="%(1j.[%F{magenta}%j%f].)"
PS1_LINE='%# '
PS1_LINE='%(!.%F{red}.%F{default})%#%f '
}
function set_xterm_title
{
local title=''
local tmux_session_name=''
local title='%n@%m'
if [[ -n "$TMUX" ]]; then
title+="`tmux display-message -p '#S'`: "
local tmux_session_name=`tmux display-message -p '#S'`
title+=" (${tmux_session_name})"
fi
# Set xterm and screen titles
if [[ -n "$DISPLAY" || -n "$TERM_PROGRAM" ]]; then
print -Pn "\e]2;%n@%m\a"
print -Pn "\e]2;${title}\a"
fi
# For Apple Terminal.app, add a link to the current directory.
@ -130,6 +133,20 @@ function set_xterm_title
fi
}
function set_tmux_window_name
{
if [[ -z "$TMUX" ]]; then
return
fi
local process="${${(z)1}[1]}"
if [[ -n "$process" ]]; then
tmux rename-window "$process"
else
tmux rename-window "`print -Pn "%2~"`"
fi
}
function set_zle_mode_info
{
if [[ -z "$1" || "$1" == 'viins' || "$1" == 'main' ]]; then