From 1d62502fc8493a9cfd110231ff42df2db67682e3 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 23 Oct 2024 23:09:05 +1300 Subject: Set window titles from Bash and tmux --- bash/bashrc.d/prompt.bash | 23 ++++++++++++++++++++++- tmux/tmux.conf | 3 +++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index e0a03438..1bf3684e 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -14,8 +14,10 @@ prompt() { PROMPT_DIRTRIM=4 fi - # Prompt has hostname via SSH outside of screen/tmux + # Start building prompt PS1= + + # Prompt has hostname via SSH outside of screen/tmux if [[ -n $SSH_CLIENT && -z $STY && -z $TMUX ]] ; then PS1=$PS1'\h:' fi @@ -39,6 +41,25 @@ prompt() { # Add terminating "$" or "#" sign PS1=$PS1'\$' + # Set xterm/rxvt window title for appropriate $TERMs + case $TERM in + xterm*|rxvt*) + + # Hard-code title-set terminfo sequences, as they're + # missing from the xterm and xterm-256color definitions + local tsl fsl + tsl="\e]2;" + fsl="\a" + + # Window title string can just be user@host:~/workdir + local title + title='\u@\h:\w' + + # Put it all together + PS1="\[${tsl}${title}${fsl}\]"$PS1 + ;; + esac + # Declare variables to contain terminal control strings local format reset diff --git a/tmux/tmux.conf b/tmux/tmux.conf index ad420528..b0091fd5 100644 --- a/tmux/tmux.conf +++ b/tmux/tmux.conf @@ -72,6 +72,9 @@ set-option -g escape-time 0 # Don't interfere with my system clipboard set-option -g set-clipboard off +# Set window titles +set-option -g set-titles on + # Only force individual windows to the smallest attached terminal size, not # whole sessions set-window-option -g aggressive-resize on -- cgit v1.2.3