How to set background color of "ANY" terminal (in bash?)
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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
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.
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.