You are not logged in.

#1 2010-11-29 01:50:51

Anikom15
Banned
From: United States
Registered: 2009-04-30
Posts: 836
Website

Magic Bash Prompt

This magical prompt will cycle through the colors of the rainbow! It'll work properly if your terminal follows ANSI colors. (i.e. it works on the Linux console)

UPDATE: Version 1.0.0 released! Includes new random_hue function for random colors!

In your .bashrc file:

# Magic Prompt 1.0.0
function next_hue
{
    color=$((31 + (++color % 7)))   # set 31 to 30 for dark on light
    PS1="\[\e[1;${color}m\]\\$ $reset" # set 1 to 0 for dark on light
}

function random_hue
{
    color=$(($RANDOM % 7 + 31)) # set 31 to 30 for dark on light
    PS1="\[\e[1;${color}m\]\\$ $reset"    # set 1 to 0 for dark on light
}

PROMPT_COMMAND="random_hue"

Try it out, and comment out your old PS1. It's cool if you hold down the return key.

Last edited by Anikom15 (2010-11-30 03:53:44)


Personally, I'd rather be back in Hobbiton.

Offline

#2 2010-11-29 03:53:57

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Magic Bash Prompt

I can confirm both that it works and that it is absolutely ridiculous. wink

Do you happen to know the trick to having multiple commands set to the PROMPT_COMMAND variable?

Offline

#3 2010-11-29 04:29:42

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Magic Bash Prompt

Hillarious waste of the PROMPT_COMMAND, but still hillarious. @drcouzelis: no, sadly this isn't something you can really get around. ZSH offers the ability to specify multiple precmd hooks.

I've condensed it into pure awesome:

next_hue() {
    color=$(( 30 + (++color % 8) ))
    echo -ne "\e[1;${color}m"    # change 1 to 0 for darker colors
}
PROMPT_COMMAND=next_hue
PS1="\$\[\e[0m\] "

Last edited by falconindy (2010-11-29 04:30:14)

Offline

#4 2010-11-29 14:37:43

Anikom15
Banned
From: United States
Registered: 2009-04-30
Posts: 836
Website

Re: Magic Bash Prompt

I figured there was some kind of pattern to it but I was too lazy to bother. I also made one that changes the prompt to a random color. I'll post it later.


Personally, I'd rather be back in Hobbiton.

Offline

#5 2010-11-29 16:22:01

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: Magic Bash Prompt

Nice to see you post something productive for once wink.


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#6 2010-11-29 16:40:02

hbekel
Member
Registered: 2008-10-04
Posts: 311

Re: Magic Bash Prompt

drcouzelis wrote:

Do you happen to know the trick to having multiple commands set to the PROMPT_COMMAND variable?

Simply do this if you already have a PROMPT_COMMAND you wish to keep:

PROMPT_COMMAND="next_hue; $PROMPT_COMMAND"

There's no reason PROMPT_COMMAND can't contain multiple commands.

Offline

#7 2010-11-29 17:14:26

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Magic Bash Prompt

move along, nothing to see here.

Last edited by falconindy (2010-11-29 18:04:45)

Offline

#8 2015-02-22 14:53:49

halimbo
Member
From: Krefeld, Germany
Registered: 2013-10-23
Posts: 67

Re: Magic Bash Prompt

this is awesome smile

Offline

Board footer

Powered by FluxBB