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.
User avatar
None1975
 
Posts: 699
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 :)
dbruce wrote:Ubuntu forums try to be like a coffee shop in Seattle. Debian forums strive for the charm and ambience of a skinhead bar in Bacau. We intend to keep it that way.
User avatar
Head_on_a_Stick
 
Posts: 8318
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).
dbruce wrote:Ubuntu forums try to be like a coffee shop in Seattle. Debian forums strive for the charm and ambience of a skinhead bar in Bacau. We intend to keep it that way.
User avatar
Head_on_a_Stick
 
Posts: 8318
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.
User avatar
None1975
 
Posts: 699
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
dbruce wrote:Ubuntu forums try to be like a coffee shop in Seattle. Debian forums strive for the charm and ambience of a skinhead bar in Bacau. We intend to keep it that way.
User avatar
Head_on_a_Stick
 
Posts: 8318
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: 3064
Joined: 2013-03-12 07:18


Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 5 guests

fashionable