You are not logged in.

#1 2009-03-01 06:15:30

orph
Member
From: Montréal, Canada
Registered: 2009-03-01
Posts: 25
Website

[SOLVED] Quick bash question (~/.bashrc stuff)

Hi!
First I have to say that I have installed Arch few days ago and it's pretty sweet stuff -- but I guess you already have heard that oh-so-many-times! wink

So there is it, I would like to change my prompt's color everytime <enter> is pressed in the terminal (well, everytime a new prompt is shown).
But so far I was only able to change my prompt's color everytime a new terminal is opened, with this code in .bashrc :

# color changing for the prompt
colors=("\[\e[0;30m\]" "\[\e[0;34m\]" "\[\e[0;32m\]" "\[\e[0;36m\]" "\[\e[0;31m\]" "\[\e[0;35m\]" "\[\e[0;33m\]" "\[\e[0;37m\]" "\[\e[1;30m\]" "\[\e[1;34m\]" "\[\e[1;32m\]" "\[\e[1;36m\]" "\[\e[1;31m\]" "\[\e[1;35m\]" "\[\e[1;32m\]" "\[\e[1;37m\]")
let R=$RANDOM%16+0
color=${colors[$R]}
prompt="${color}\u@\h:\w\$\[\e[0m\] "

# the prompt
PS1=$prompt

Thanks.

Last edited by orph (2009-03-01 16:10:57)


I KISS you.

Offline

#2 2009-03-01 11:03:20

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

Re: [SOLVED] Quick bash question (~/.bashrc stuff)

You could use the PROMPT_COMMAND:

colors=("\[\e[0;30m\]" "\[\e[0;34m\]" "\[\e[0;32m\]" "\[\e[0;36m\]" "\[\e[0;31m\]" "\[\e[0;35m\]" "\[\e[0;33m\]" "\[\e[0;37m\]" "\[\e[1;30m\]" "\[\e[1;34m\]" "\[\e[1;32m\]" "\[\e[1;36m\]" "\[\e[1;31m\]" "\[\e[1;35m\]" "\[\e[1;32m\]" "\[\e[1;37m\]")

PROMPT_COMMAND='let R=$RANDOM%16+0;color=${colors[$R]};PS1="${color}\u@\h:\w\$\[\e[0m\] "'

Offline

#3 2009-03-01 16:10:24

orph
Member
From: Montréal, Canada
Registered: 2009-03-01
Posts: 25
Website

Re: [SOLVED] Quick bash question (~/.bashrc stuff)

Thanks!


I KISS you.

Offline

Board footer

Powered by FluxBB