Register
It is currently Sun Oct 26, 2014 1:40 am

a script to set terminal colors with ansi


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sun Nov 18, 2007 8:28 pm   

Joined: Sun Nov 18, 2007 8:28 am
Posts: 6
I've been trying to make a script to choose ansi colors to set the terminal.
So far I have:

Code:
#!/bin/bash

clear
echo "Hello, you are logged in as " $USER". What foreground color would you like? "

sleep 1


echo "..........................."
echo "...........MENU............"
echo
echo "1 black "
echo "2 red "
echo "3 green "
echo "4 yellow"
echo "5 blue"
echo "6 purple"
echo "7 cyan"
echo "8 white"



read fore
while [ "$fore" != 0 ];
do
        case $fore in
                1)  clear;
                  export front=[30m ;
                  ;;
                2)  clear;
                  export front=[31m ;
                  ;;
                3)  clear;
                  export front=[32m ;
                  ;;
                4)  clear;
                  export front=[33m ;
                  ;;
                5)  clear;
                  export front=[34m ;
                  ;;
                6)  clear;
                  export front=[35m ;
                  ;;
                7)  clear;
                  export front=[36m ;
                ;;
esac
done
clear
echo "What background color would you like? "

sleep 1

#The Menu
echo "..........................."
echo "...........MENU............"
echo
echo "1 black "
echo "2 red "
echo "3 green "
echo "4 yellow"
echo "5 blue"
echo "6 purple"
echo "7 cyan"
echo "8 white"

read back
while [ "$back" != 0 ];
do
        case $back in

                1)  clear;
                  export rear=[40m ;
                  ;;
                2)  clear;
                  export rear=[41m ;
                  ;;
                3)  clear;
                  export rear=[42m ;
                  ;;
                4)  clear;
                  export rear=[43m ;
                  ;;
                5)  clear;
                  export rear=[44m ;
                  ;;
                6)  clear;
                  export rear=[45m ;
                  ;;
                7)  clear;
                  export rear=[46m ;
                  ;;
                8)  clear;
                  export rear=[47m ;
                  ;;
esac
done
while [ "$back" = "$fore" ];
        do
        echo "You can't read that!!!!"
        ;;

while [ "$back"  != "$fore" ];
        do
        PS1="\[\033[0;$front;$rear\u@\h:\w\$ \]";
        ;;
done
exit



I'm not sure about terminating the while statements with done. It seems to give error messages. I also don't know if I need some sort of eval statement for setting PS1 . The error message write now is from the PS1 line but that is only because I had to # the last two while statements to see what else was happening.

Suggestions?


Top
 Profile WWW  
 PostPosted: Wed Nov 21, 2007 11:24 am   

Joined: Sun Nov 18, 2007 8:28 am
Posts: 6
I couldn't get that script to work so I started over with:

Code:
PS3="Enter foreground color choice:  "
select fgcc in black red green yellow blue purple cyan white exit
do
case ${fgcc} in
  "black") export fgc=30;;
  "red") export fgc=31;;
  "green") export fgc=32;;
  "yellow") export fgc=32;;
  "blue") export fgc=34;;
  "purple") export fgc=35;;
  "cyan") export fgc=36;;
  "white") export fgc=37;;
  "exit") exit;;
  *) echo "Invalid Choice"
     exit;;
esac
break
done

PS3="Enter background color choice:  "
select bgcc in black red green yellow blue purple cyan white exit
do
case ${bgcc} in
  "black") export bgc=40;;
  "red") export bgc=41;;
  "green") export bgc=42;;
  "yellow") export bgc=33;;
  "blue") export bgc=44;;
  "purple") export bgc=45;;
  "cyan") export bgc=46;;
  "white") export bgc=47;;
  "exit") exit;;
  *) echo "Invalid Choice"
     exit;;
esac
break
done

#PS1=$'[\e[0;'"$fgc;$bgc"'\u@\h:\w\$ \]'
export PS1=$"\[\e[0;$fgc;"$bgc"m\u@\h:\w\$ \]"


Which gives the output that I can use to set the terminal colors but doesn't actually set it. ?

Another question would be how to use it so that the terminal colors changed randomly ever time a command was entered at the command line.


Top
 Profile WWW  
 PostPosted: Sat Nov 24, 2007 5:04 pm   

Joined: Sun Nov 18, 2007 8:28 am
Posts: 6
putting
Code:
PS1=$"\[\e[0;$fgc;"$bgc"m\u@\h:\w\$ \]"
at the end and running the script with . or source makes it work fine.


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP