[arch-general] fish-style prompt for bash

b4283 da.mi.spirit at gmail.com
Sun Sep 6 05:43:57 EDT 2009


Hi,
I just finished writing a fancier prompt for bash, which showing 
directories in an abbreviated form just like the fish shell does.

function _prompt {
    _dir_abbr=$(temp=$(echo "${PWD/$HOME/~}" |sed -r 
's/(\/.)[^/]*/\1/g'); echo ${temp:0:$(( ${#temp} - 1 ))})
    _ps1="$(basename "${PWD/$HOME/~}")"
    if [ ${#_ps1} -gt 25 ]; then
        _ps1="${_ps1:0:7}...${_ps1: -7}"
    fi
    echo -n "$_dir_abbr$_ps1"
}

just quote the function in the $PS1 like this (e.g.):
PS1='$(_prompt)] '

enjoy!


More information about the arch-general mailing list