Give terminal windows a very short title indicating path, starting with the most likely information-dense part of the path, the immediate (last) folder
- gnome terminal window titles “path” first
- terminal window title ubuntu
- command line concise terminal title
- giving short window title based on most relevant parts of directory path first
How are there not 100 command line power users each giving their precise preference as an answer to this question?
OK at least i have found what is currently in my Debian (default?) .bashrc:
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
But i removed the \u@\h:
part, which must be “user@host”, to at least make it shorter, but that’s still showing up…
Ah, oops, i was overriding it here:
## Set terminal title; keep pre-existing history prompts
PROMPT_COMMAND='history -a; history -n; echo -en "\033]0;$(whoami)@$(hostname)|$(pwd|cut -d "/" -f 4-100)\a"'
Removing the $(whoami)
does have an impact there.
Solution
Here it is all together, with tons of help from @wolcen:
function rev_path() {
IFS='/'
echo $1 | awk '{
for (i=NF; i>=1; i--) {
printf "%s%s", $i, i == 1 ? ORS : " 〈 "
}
}'
}
## Set terminal title; keep pre-existing history prompts
PROMPT_COMMAND='history -a; history -n; echo -en "\033]0;$(rev_path $(pwd|cut -d "/" -f 4-100 ))\a"'