bash PROMPT_COMMAND to set (restore) terminal title
dblume

dblume commited on 2024-04-27 13:45:21
Showing 2 changed files, with 7 additions and 0 deletions.


If tmux, vim, etc. set the terminal title, then we want
the shell to restore the terminal title when they're done.

Also leave a note to vim to easily test whether C-i can be mapped
independently of Tab.
... ...
@@ -150,6 +150,9 @@ case "$-" in
150 150
   # gnome-terminal can't distinguish C-i vs Tab, have i3wm use alacritty
151 151
   export TERMINAL=alacritty
152 152
 
153
+  # This sets the terminal title
154
+  PROMPT_COMMAND="echo -ne \"\033]0;$HOSTNAME\007\""
155
+
153 156
  ;;
154 157
 esac
155 158
 
... ...
@@ -50,6 +50,10 @@ nnoremap <cr> :noh<cr><cr>
50 50
 
51 51
 " Shift-Tab switches to prev buffer
52 52
 " (Not remapping Tab because Ctrl-i in use as 'go to next jump pos')
53
+" Test with this:
54
+" vim -Nu NONE +'nno <C-i> :echom "C-i pressed"<cr>' +'nno <tab> :echom "Tab pressed"<cr>'
55
+""nnoremap <C-i> <C-i>
56
+""nmap <Tab> :bn<cr>
53 57
 nnoremap <S-Tab> :bp<cr>
54 58
 
55 59
 " Use yy to yank a whole line, use Y to yank to end of line like C and D
56 60