Results 1 to 7 of 7

Thread: Function "ppwd" in $PS1

  1. #1

    Default 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 :

    Code:
    :~> 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:
    Code:
        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,

  2. #2
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    19,854
    Blog Entries
    14

    Default Re: Function "ppwd" in $PS1

    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
    Code:
    man bashrc
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    https://en.opensuse.org/openSUSE:Board#Members
    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,157

    Default Re: Function "ppwd" in $PS1

    This is on 13.1, but is it very different on 42.3?
    Code:
    henk@boven:~> man bashrc
    Er is geen pagina over bashrc
    henk@boven:~> LANG=C man bashrc
    No manual entry for bashrc
    henk@boven:~>
    Henk van Velden

  4. #4

    Default Re: Function "ppwd" in $PS1

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

    Thanks for the answers !

    bests,

    EDIT: I too have nothing for
    Code:
    man bashrc

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,157

    Default Re: Function "ppwd" in $PS1

    Thanks for reporting back.

    That whole terminfo thing reminds me off old times.

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

  6. #6
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    12,631
    Blog Entries
    3

    Default Re: Function "ppwd" in $PS1

    Quote Originally Posted by ghostjoad View Post
    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)
    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.
    openSUSE Leap 15.1; KDE Plasma 5;
    testing Leap 15.2Alpha

  7. #7

    Default Re: Function "ppwd" in $PS1

    Quote Originally Posted by nrickert View Post
    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 !

    Quote Originally Posted by hcvv
    In fact I have here man pages about term(4), terminfo(4) and terminfo_c(4) on paper dated 1995 before me.
    Old papers are always a lot of fun !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •