diff --git a/tmux/.tmux.conf b/tmux/.tmux.conf index 25a85e6..8986eb5 100644 --- a/tmux/.tmux.conf +++ b/tmux/.tmux.conf @@ -43,12 +43,13 @@ bind - run-shell 'v="#{@venv}"; d="#{pane_current_path}"; if [ -n "$v" ]; then t # its global env carries one), regardless of what the source pane had. bind c new-window -e VIRTUAL_ENV= -# ssh panes: the shell sets #{@ssh_host} and the pane title to the alias (see -# zsh/lib/interactive.zsh); a remote that sets its own title overrides the -# latter. Label ssh panes by title in the window name and, only in windows with -# an ssh pane, in the pane border. -set -g automatic-rename-format '#{?#{@ssh_host},#{=40:pane_title},#{?pane_in_mode,[tmux],#{pane_current_command}}#{?pane_dead,[dead],}}' -set -g pane-border-format '#{?#{@ssh_host},#[bold] #{=60:pane_title} #[default],}' +# ssh panes: the shell sets #{@ssh_host} to the alias (see +# zsh/lib/interactive.zsh). Label them with the remote's title if it is a bare +# user@host (as our server zsh pins it), else with the alias; in the window +# name and, only in windows with an ssh pane, in the pane border. +set -g @ssh_label '#{?#{m/r:^[^@: ]+@[^@: ]+$,#{pane_title}},#{pane_title},#{@ssh_host}}' +set -g automatic-rename-format '#{?#{@ssh_host},#{=40:#{E:@ssh_label}},#{?pane_in_mode,[tmux],#{pane_current_command}}#{?pane_dead,[dead],}}' +set -g pane-border-format '#{?#{@ssh_host},#[bold] #{=60:#{E:@ssh_label}} #[default],}' set-hook -g window-layout-changed \ 'if -F "#{P:#{@ssh_host}}" "set -w pane-border-status top" "set -wu pane-border-status"' diff --git a/zsh/lib/interactive.zsh b/zsh/lib/interactive.zsh index dd1da2e..f449da1 100644 --- a/zsh/lib/interactive.zsh +++ b/zsh/lib/interactive.zsh @@ -110,7 +110,7 @@ zstyle :bracketed-paste-magic paste-finish pastefinish ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste) # Mirror the ssh destination into a per-pane tmux option; .tmux.conf labels ssh -# panes (window name, pane border only in windows with ssh panes) by title. +# panes with it or the remote's user@host title. _ssh_host_tmux() { local -a set=(set -p -t $TMUX_PANE @ssh_host "$1") [[ -n $1 ]] || set=(set -pu -t $TMUX_PANE @ssh_host) @@ -146,8 +146,8 @@ _ssh_host_preexec() { [[ -n $host ]] || return _ssh_host_tmux $host _ssh_host_set=1 - # pane title starts as the alias; a remote that sets its own title wins. - # Runs after OMZ's preexec, so this replaces its "ssh ..." title. + # title the pane with the alias until the remote sets one; runs after + # OMZ's preexec, so this replaces its "ssh ..." title print -rn -- $'\e]2;'"$host"$'\e\\' } _ssh_host_precmd() {