Thursday, May 2, 2024
13
rated 0 times [  13] [ 0]  / answers: 1 / hits: 8261  / 1 Year ago, mon, november 21, 2022, 8:31:59

Currently, my bash terminal/tab title is set based on the directory I'm in. For example:



bob@bobscomputer:~/i/had/some/great/pie/yesterday


This isn't very useful if I have multiple tabs open side-by-side. For example, if I have 4 tabs of the above dir open side-by-side, all I see is



bob@bobscomputer:~/i/had...


4 times.



I'd like all my terminal titles to be set automatically to just the last part of the path. In the example above, I'd like the title to be



yesterday


Obviously, the title should change when I change directories. I'd like to do this without changing my prompt, so the prompt and the terminal title should be different.



Is there a way to do this?


More From » command-line

 Answers
1

Why do you want to do it without modifying your PS1 variable? That is the correct way to do it.



If you run the following, you'll get what you want:



export PS1="[e]0;Wa]${debian_chroot:+($debian_chroot)}[033[01;32m]u@h[033[00m]:[033[01;34m]w[033[00m]$ "



This is just taking the default prompt:



export PS1="[e]0;u@h: wa]${debian_chroot:+($debian_chroot)}[033[01;32m]u@h[033[00m]:[033[01;34m]w[033[00m]$ "



... and replacing u@h: w with W.



You can do the same thing with any command that echoes the right escape code:



echo -en "e]0;${PWD##*/}a"



... but then you'd be constantly fighting bash to stop it from doing it using PS1 (the best way).


[#26250] Monday, November 21, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ugeeport

Total Points: 181
Total Questions: 108
Total Answers: 99

Location: El Salvador
Member since Tue, Jun 29, 2021
3 Years ago
ugeeport questions
;