Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I wrote my PS1 in Python once, but on review it turned out much better to have it completely in shell:

    set_PS1()
    {
        local RESET=$(tput sgr0 )
        local BOLD=$(tput bold )
        local RED=$(tput setaf 1 )
        local GREEN=$(tput setaf 2 )
        local YELLOW=$(tput setaf 3 )
        local BLUE=$(tput setaf 4 )
        local MAGENTABG=$(tput setab 5 )
        local CYAN=$(tput setaf 6 )

        local WHOAMI='\u'
        local WHERE='\w'
        local HOSTNAME='\h'
        local DATE='\D{%Y-%m-%d %H:%M:%S}'
        local LAST_RET='${?#0}'

        local LINE_1="$YELLOW$DATE $GREEN$WHOAMI$RED@$CYAN$HOSTNAME $BLUE$BOLD$WHERE$RESET"
        local LINE_2="\\[$MAGENTABG\\]$LAST_RET\\[$RESET\\]"'\$ '

        PS1="$LINE_1\n$LINE_2"

        unset -f set_PS1
    }

    set_PS1

sauce: https://codereview.stackexchange.com/q/174019


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: