Customize your Bash Prompt

Share your own howto's etc. Not for support questions!

Customize your Bash Prompt

Postby None1975 » 2017-12-09 13:31

Hello guys :D Here is a nice project- EzPrompt Easy Bash PS1 Generator. It is is a project of nice guy-Josh Matthews. Very easy to customizing your Bash Prompt.
OS: Debian 9.4 / WM: Xmonad
Debian Wiki | DontBreakDebian, My config files in github
Linux User #607425
User avatar
None1975
 
Posts: 481
Joined: 2015-11-29 18:23
Location: Lithuania, Vilnius

Re: Customize your Bash Prompt

Postby Head_on_a_Stick » 2017-12-09 13:50

Here's one not in your link:
Code: Select all
\e[31m${?#0}\e[0m\

That code will cause the error status of the last command to be printed in red text but only if it is non-zero (ie, if the command failed in some way).

Example .bashrc:
Code: Select all
PS1='\h: \w \e[31m${?#0}\e[0m\$ '

Looks like this:

Image

EDIT: it also works for mksh, if you prefer a lighter, faster, less buggy shell :)
"Il semble que la perfection soit atteinte non quand il n'y a plus rien à ajouter, mais quand il n'y a plus rien à retrancher."
— Antoine de Saint Exupéry, Terre des Hommes (1939).
User avatar
Head_on_a_Stick
 
Posts: 7565
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Customize your Bash Prompt

Postby Head_on_a_Stick » 2017-12-09 14:07

Head_on_a_Stick wrote:Here's one not in your link

Actually, I was wrong about that but you might want to tell Mr. Matthews about the built-in function I posted above because his function:
Code: Select all
function nonzero_return() {
   RETVAL=$?
   [ $RETVAL -ne 0 ] && echo "$RETVAL"
}

Will be _much_ slower than my version (and opens up another subshell).
"Il semble que la perfection soit atteinte non quand il n'y a plus rien à ajouter, mais quand il n'y a plus rien à retrancher."
— Antoine de Saint Exupéry, Terre des Hommes (1939).
User avatar
Head_on_a_Stick
 
Posts: 7565
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Customize your Bash Prompt

Postby None1975 » 2017-12-09 14:24

Actually, I was wrong about that but you might want to tell Mr. Matthews about the built-in function I posted above because his function:

Thank you, Head_on_a_Stick. I’m going to let him know.
OS: Debian 9.4 / WM: Xmonad
Debian Wiki | DontBreakDebian, My config files in github
Linux User #607425
User avatar
None1975
 
Posts: 481
Joined: 2015-11-29 18:23
Location: Lithuania, Vilnius

Re: Customize your Bash Prompt

Postby Head_on_a_Stick » 2017-12-09 14:31

^ It's OK, I've opened an Issue on github already ;)

https://github.com/jmatth/ezprompt/issues/14
"Il semble que la perfection soit atteinte non quand il n'y a plus rien à ajouter, mais quand il n'y a plus rien à retrancher."
— Antoine de Saint Exupéry, Terre des Hommes (1939).
User avatar
Head_on_a_Stick
 
Posts: 7565
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Customize your Bash Prompt

Postby debiman » 2017-12-10 08:19

Head_on_a_Stick wrote:Here's one not in your link:
Code: Select all
\e[31m${?#0}\e[0m\

That code will cause the error status of the last command to be printed in red text but only if it is non-zero (ie, if the command failed in some way).

Example .bashrc:
Code: Select all
PS1='\h: \w \e[31m${?#0}\e[0m\$ '

Looks like this:

Image

EDIT: it also works for mksh, if you prefer a lighter, faster, less buggy shell :)

such a useful addition to any prompt!
User avatar
debiman
 
Posts: 2405
Joined: 2013-03-12 07:18


Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 2 guests

fashionable