LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-13-2008, 01:34 PM   #1
xmo
LQ Newbie
 
Registered: Aug 2008
Posts: 3

Rep: Reputation: 0
How to set background color of "ANY" terminal (in bash?)


Hi all,

I'm trying to set the background color of a terminal to black or something dark. I understand that usually this can be set by some argument like "-bg black". But each terminal has different syntax. I wonder if there is a more "universal" way to set this for any terminals.

For example I learned bash prompt can be set to specific color by customizing the PS1 variable like this, which works on any terminals:
Code:
# invert foreground and background color
PS1="\[$(tput rev)\]$PS1\[$(tput sgr0)\]"
# set foreground to red
PS1="\[$(tput setaf 1)\]$PS1\[$(tput sgr0)\]"
But that only alter the background color for the prompt. I tried remove the reset-color-to-default part (\[$(tput sgr0)\]), then I got mixed color on the screen which looks horrible.

I also tried "setterm -background black", and it seems doesn't work on any terminals: gnome-terminal, konsole, yakuake, build-in-terminal in krusader. I'm running Ubuntu 8.04.1

So... is there a way to set this automatically for any terminal? Maybe some "magic lines" I can put into a *rc file?

Thanks for looking at my first post here

mo
 
Old 08-13-2008, 04:13 PM   #2
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: PCLinux, Slackware
Posts: 6,990

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Not sure if this is what you want but, if you open a terminal, go to Settings, click configure konsole, there is a schema tab under which you can set foreground/background etc. I'm not using Ubuntu so I'm not sure if that makes a difference.
 
Old 08-13-2008, 05:26 PM   #3
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 234Reputation: 234Reputation: 234
To my knowledge, there is no universal way of setting these global configurations for all terminal programs. They're independent from one another when it comes to specific style like configurations.

I always stick with one terminal and customize it, not bothering with the others.
 
Old 08-13-2008, 05:39 PM   #4
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,088

Rep: Reputation: 196Reputation: 196
What about adding this to your .bashrc

Code:
echo -e "\E[42m"
clear
Seems to work in a very quick test in Konsole and xterm. For colour codes see http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
 
Old 08-13-2008, 06:05 PM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by arizonagroovejet View Post
What about adding this to your .bashrc

Code:
echo -e "\E[42m"
clear
Seems to work in a very quick test in Konsole and xterm. For colour codes see http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
That's only going to set the prompt, not the background of the actual terminal, the whole terminal.
 
Old 08-13-2008, 10:30 PM   #6
xmo
LQ Newbie
 
Registered: Aug 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for all of your replies.

2trickykid:
You're definitely guru on this. I guess I'll give up if even you don't know how to do it
May I ask one more question? What if you have to log on remotely on different computers? Since the configure file will be on the client side, the only way is to carry it around all the time, is it?
BTW, just curious, which terminal do you stick with // no intent to turn this thread into a terminal war
 
Old 08-14-2008, 05:04 AM   #7
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,088

Rep: Reputation: 196Reputation: 196
Quote:
Originally Posted by trickykid View Post
That's only going to set the prompt, not the background of the actual terminal, the whole terminal.
Did you actually try it? In my tests it does not just set the background colour of the prompt. It does cause the background colour of the prompt to be changed but it also causes the background of everything you type after the prompt to be changed and the clear command causes the background of the whole terminal window to be changed.
 
Old 08-14-2008, 05:48 AM   #8
xmo
LQ Newbie
 
Registered: Aug 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by arizonagroovejet View Post
Did you actually try it? In my tests it does not just set the background colour of the prompt. It does cause the background colour of the prompt to be changed but it also causes the background of everything you type after the prompt to be changed and the clear command causes the background of the whole terminal window to be changed.
Hi,
Sorry. I tried it before in CLI and it doesn't work. Now I put it in a shell script and it DOES set the whole terminal to black! I don't understand the mechanism ...
However once I go beyond that screen, the color turned back to normal (also happens on current line when I hit backspace, but that's more trivial). Do you think there is anyway to avoid that?

Thank you
 
Old 08-14-2008, 06:37 AM   #9
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,088

Rep: Reputation: 196Reputation: 196
Hmmm. Actually on further experimentation the background colour is easily lost. E.g. on my system ls is aliased to 'ls --color' by default and so running ls causes the background set by the echo command to be lost.
I suspect there is just no way to set a background reliably exception by configuring the terminal application you're using.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why "bash-2.05b$" in Terminal instead of "username@localhost username" jayelitumbiolo Linux - General 9 10-04-2009 04:16 AM
Xfce terminal shows "bash-3.11" instead of the path jsmith6 Slackware 5 01-13-2008 03:30 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 11:18 PM
Make "ls" command show colors without "--color=always" switch SharpyWarpy Linux - General 4 07-17-2007 12:00 AM
Adjusting the color, "BLUE" in the terminal scoTtkIm Linux - Newbie 2 09-01-2004 07:53 AM


All times are GMT -5. The time now is 06:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration