Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash prompt #138

Open
boyska opened this issue Aug 25, 2014 · 10 comments
Open

bash prompt #138

boyska opened this issue Aug 25, 2014 · 10 comments
Assignees
Milestone

Comments

@boyska
Copy link
Member

boyska commented Aug 25, 2014

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 boyska self-assigned this Aug 25, 2014
@boyska
Copy link
Member Author

boyska commented Sep 17, 2014

simple, no colors, exit code at line beginning

export PS1='[\u ($?)] \w \$ '

@boyska boyska modified the milestone: v1.1 Sep 20, 2014
@AreYouLoco
Copy link

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
Copy link

Nhoya commented Jun 15, 2015

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
Copy link

Nhoya commented Jun 15, 2015

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
Copy link
Member Author

boyska commented Jun 15, 2015

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
Copy link

Nhoya commented Jun 15, 2015

In wich way? What commands u use?

@Nhoya
Copy link

Nhoya commented Jun 15, 2015

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

@boyska
Copy link
Member Author

boyska commented Jun 16, 2015

here is a screenshot of how it is "wrong"

sshot

@boyska
Copy link
Member Author

boyska commented Jun 16, 2015

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
Copy link
Member Author

boyska commented Jun 16, 2015

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

@ghost ghost modified the milestone: v1.1 Jul 13, 2015
@boyska boyska modified the milestone: v1.1.1 Jul 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants