Search code examples
bashunix.profile

How do i make the colour of the $ bit in a terminal change colour every line?


currently i have this:

function xtitle2()      # Adds some text in the terminal frame.
{
export var1=`echo $HOSTNAME | perl -pe 's/^([a-zA-Z0-9]+)\.(.*)$/\1/g'`
export var2=`pwd`
echo -n -e "\033]0;$var1 : $var2\007"

a=$(( $a + 1 ))
if (( $a > 36 ))
then
    a=30
fi

}


PROMPT_COMMAND="xtitle2"

PS1="\e[0;${a}m$ \e[m"

but it only changes the colour when i do

$. ~/.profile

but i want it to change the colour every time any command is entered...

how do i do this?

EIDT:

ended up going with this:

function xtitle2()      # Adds some text in the terminal frame.
{
export var1=`echo $HOSTNAME | perl -pe 's/^([a-zA-Z0-9]+)\.(.*)$/\1/g'`
export var2=`pwd`
echo -n -e "\033]0;$var1 : $var2\007"

if [ -z $a ]
then
    a=29
fi

a=$(( $a + 1 ))
if (( $a > 36 ))
then
    a=30
fi
PS1="\[\033[${a}m\]$\[\e[0m\]"
}


export PROMPT_COMMAND="xtitle2"

Solution

  • Include "$(xtitle2)" in your PS1 setting

    Of course you need to refactor xtitle2 a bit; the good news is that you won't have to abuse PROMPT_COMMAND for this purpose anymore. Also, all the vars except a could be local.

    You will want to use $(($HISTCMD % 30)) instead of the jumble with variable a