I’ve just installed Leap 42.3, and out of curiosity I took a look at the default $PS1, which is :
:~> echo $PS1
\$(ppwd)\]\u@\h:\w>
So I went digging around this ppwd, which appears to be a function defined in some obscure (as far as I understand) part of /etc/bash.bashrc (from line 146), where it is defined as:
if path tput hs 2>/dev/null || path tput -T $TERM+sl hs 2>/dev/null ; then
...
ppwd () {
local dir
local -i width
test -n "$TS1" || return;
dir="$(dirs +0)"
let width=${#dir}-18
test ${#dir} -le 18 || dir="...${dir#$(printf "%.*s" $width "$dir")}"
if test ${#TS1} -gt 17 ; then
printf "$TS1" "$USER" "$HOST" "$dir" "$HOST"
else
printf "$TS1" "$USER" "$HOST" "$dir"
fi
}
else
ppwd () { true; }
fi
Could someone please help me to understand better how this works, and when it is useful ?
That’s my first post here, so I hope this is the right place to ask this questions !
Ok, so after a little bit more tinkering, it appears that this function is used to set the title of the window in xterm for instance, and is not used in more “advanced” terminal emulator such as Konsole. Anyway, this was a nice discovery of the tput program, and I found this reference: https://www.gnu.org/software/termutils/manual/termutils-2.0/html_chapter/tput_1.html for those interested (I found the man entry, well… not comprehensive ).
I think “ppwd” supposed to “print present working directory”. It is used to generate the prompt, and that supposed to remind you where you are. The definition is a bit hard to follow. I think it is checking width to see if there is enough space on the command line. And for some terminals, it is instead used to put the directory in the title bar.
I played with xterm, and this is exactly what happens: this is used to “pretty print” the path in the window title, and to cut it to 18 or so characters when it is too long.