AvANa-BBS / freepto-lb

Encrypted GNU/Linux OS (based on Debian Wheezy) which can be installed on USB flash drive. Freepto is designed for encrypt your communications, carry your documents in secure way and save your anonymity.
http://www.freepto.mx/
43 stars 14 forks source link

bash prompt #138

Open boyska opened 10 years ago

boyska commented 10 years ago

Our current bash prompt is rather basic. An improved one is not just a vanity feature: it also aids in testing. Especially, it would be good to see the last exit code appear in the prompt.

boyska commented 9 years ago

simple, no colors, exit code at line beginning

export PS1='[\u ($?)] \w \$ '
AreYouLoco commented 9 years ago

advanced, colors, timestamp, exit code, directory

export PS1="${debian_chroot:+($debian_chroot)}[\e[00;33m][\t][\e[0m] $(tput rev)[$(tput sgr0)] \u@\h:[$(tput rev)]\w[$(tput sgr0)][$(tput bold)] \$ [$(tput sgr0)]"

Nhoya commented 9 years ago

What about that?

PS1="\[\e[00;37m\]┌─[\t][\[\e[0m\]\[\e[01;31m\]\\$\[\e[0m\]\[\e[00;37m\]]\n└─\\[\e[0m\]\[\e[01;32m\]\u\[\e[0m\]\[\e[00;37m\]@\[\e[0m\]\[\e[01;33m\]\h\[\e[0m\]\[\e[00;37m\]:[\[\e[0m\]\[\e[00;36m\]\w\[\e[0m\]\[\e[00;37m\]]\[\e[0m\]

is a lil more colorful.. but miss the exitcode D:

Nhoya commented 9 years ago
errorc(){
exit_=$?

    if [ $exit_ -ne 0 ]; then
        echo -e "\033[01;31m✘ $exit_\033[0m"
    else echo -e "\033[01;32m✓\033[0m"
        fi
}

who_(){ 
    if [ "$EUID" -ne 0 ]; then
        echo -e "$"
    else
        echo -e "\033[01;31m#\033[0m"
    fi
}

PS1="\u[\[\e[34m\]\w\[\e[m\]]\`errorc\` \`who_\` "
boyska commented 9 years ago

on my computer it does not work properly: it wraps in a strange & wrong way when the line exceeds the width of the window.

Nhoya commented 9 years ago

In wich way? What commands u use?

Nhoya commented 9 years ago

And wich terminal emu? I tested on guake and it works properly

boyska commented 9 years ago

here is a screenshot of how it is "wrong"

sshot

boyska commented 9 years ago

this seems to work fine


    promptunicode=1
    freeptoprompt() {
    exit_=$?
    if [[ $promptunicode -eq 1 ]]; then
    ok_symbol=$'\u2713'
    no_symbol=$'\u2717'
    else
    ok_symbol="."
    no_symbol="x"
    fi
    LIGHTGREEN="\[\033[1;32m\]"
    LIGHTRED="\[\033[1;31m\]"
    CYAN='\e[0;36m'
    WHITE="\[\033[0;37m\]"
    RESET="\[\033[0;00m\]"
    dollar="\\$"
    [[ $EUID -eq 0 ]] && dollar="$LIGHTRED$dollar$RESET"
    if [[ $exit_ -eq 0 ]]; then
    last="${LIGHTGREEN}$ok_symbol$RESET"
    else
    last="${LIGHTRED}$no_symbol:$exit_$RESET"
    fi
    PS1="\u[$CYAN\w$RESET]$last $dollar "
    }
    PROMPT_COMMAND=freeptoprompt

It can run in two modes: the default is unicode unicode the other is ascii-compatible ascii

The default is unicode, but at any time you can switch just setting promptunicode=0

boyska commented 9 years ago

b39ef4a8e0f8f59304dc42fa7 should be ok, with also some minor improvement on the previously-posted screenshot (cyan dirname, better user color handling, local variables everywhere).

I'm wondering if a separate package (submodule) would be appropriate for such a small enhancement. Pro: modular, updatable for previous freepto users Con: a package for one file with one dependency (bash-completion) ? Maybe we could aggregate some more stuff in there.