1

My Turnkeylinux machine uses the following PS1 environment variable for bash prompt:

PS1="${debian_chroot:+($debian_chroot)}\[\033[01;33m\]\u@\h \[\033[01;34m\]$(promptpath)\[\033[00m\]\$"

I plugged the above into what is essentially a stock "Debian GNU/Linux 6.0 \n \l" and it complained about "promptpath" being unavailable.

I tried "which promptpath", and its result was NULL (it found nothing). Since promptpath doesn't seem to be a program, what is it?

What must I do to make promptpath available on the stock Debian machine so that the prompt works without any changes?

starlocke
  • 223
  • 2
  • 11
  • What does `which promptpath` return on the Turnkey machine? – nickgrim Oct 23 '12 at 15:32
  • 1
    Run `type promptpath` on the Turnkey machine. This will show what it is. Likely, it's a TurnKey Linux-ism, where it's some function defined in the system-wide bash_profile. If that's the case, you can try to replicate the function, or just remove it from your Debian $PS1. – cjc Oct 23 '12 at 15:36
  • ```type``` -- learned a new command. Thanks :3 – starlocke Oct 23 '12 at 15:38

1 Answers1

2

I looked into my ~/.bashrc and promptpath is some kind of user-defined function.

# Set prompt path to max 2 levels for best compromise of readability and usefulness
promptpath () {
    realpwd=$(realpath $PWD)
    realhome=$(realpath $HOME)

    # if we are in the home directory
    if echo $realpwd | grep -q "^$realhome"; then
        path=$(echo $realpwd | sed "s|^$realhome|\~|")
        if [ $path = "~" ] || [ $(dirname $path) = "~" ]; then
            echo $path
        else
            echo $(basename $(dirname $path))/$(basename $path)
        fi
        return
    fi

    path_dir=$(dirname $PWD)
    # if our parent dir is a top-level directory, don't mangle it
    if [ $(dirname $path_dir) = "/" ]; then
        echo $PWD
    else
        path_parent=$(basename $path_dir)
        path_base=$(basename $PWD)

        echo $path_parent/$path_base
    fi
}

I simply copied the TurnkeyLinux ~/.bashrc to my Debian machine.

starlocke
  • 223
  • 2
  • 11