Function "ppwd" in $PS1

Hello folks,

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 !

bests,

Hi, welcome,

I hate do post answers like this ( kind of RTFM answerr ) but given the knowlegde you show in your question, I’d say

man bashrc

This is on 13.1, but is it very different on 42.3?

henk@boven:~> man bashrc
Er is geen pagina over bashrc
henk@boven:~> LANG=C man bashrc
No manual entry for bashrc
henk@boven:~>

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 :slight_smile: ).

Thanks for the answers !

bests,

EDIT: I too have nothing for

man bashrc

Thanks for reporting back.

That whole terminfo thing reminds me off old times. :slight_smile:

In fact I have here man pages about term(4), terminfo(4) and terminfo_c(4) on paper dated 1995 before me. rotfl!

I’m not completely sure. I turn that stuff off.

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.

Thanks !

Old papers are always a lot of fun :smiley: !