Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Customize your Bash Prompt

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
None1975
df -h | participant
df -h | participant
Posts: 1388
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 45 times
Been thanked: 65 times

Customize your Bash Prompt

#1 Post by None1975 »

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 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Customize your Bash Prompt

#2 Post by Head_on_a_Stick »

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 :)
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Customize your Bash Prompt

#3 Post by Head_on_a_Stick »

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).
deadbang

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1388
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 45 times
Been thanked: 65 times

Re: Customize your Bash Prompt

#4 Post by None1975 »

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 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Customize your Bash Prompt

#5 Post by Head_on_a_Stick »

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

https://github.com/jmatth/ezprompt/issues/14
deadbang

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: Customize your Bash Prompt

#6 Post by debiman »

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!

Post Reply