views:

199

answers:

3

Good Evening,

I am pretty new to Unix so maybe this mini project is too ambitious. Hoping someone could point in in the right direction.

Working in a cubicle and I can't see how light it is outside. In general I use a yellow terminal in the morning (sunny) and a black/green past 3:00 (night).

What I would like to do (partly just to practice my bash). Is to write a script that will at 3:00 change the color of all of my terminals. If that works maybe I will make them change every hour or something like that. Would that be safe? Is this possible?

Here are some of my specs: Solaris 10 Bash shell Gnome

I am looking at this right now: http://stackoverflow.com/questions/974599/change-gnome-terminal-theme-programmatically/976959#976959

A: 

Use cron, it's the Unix job scheduler. And set it to run a command that changes .bashrc like in the question you linked. The problem is that it will work only for new terminals, if you have some opened it won't change them.

Daniel Velkov
Hmmm, thanks for the comment however I rarely close my terminals so this probably will not work.
sixtyfootersdude
+1  A: 

If I were doing this, I'd start with PROMPT_COMMAND. Bash will run that script just before displaying a prompt.

You have a couple of choices. You could have a script itself inside PROMPT_COMMAND:

PROMPT_COMMAND='if [ is_morning ]; then echo "MORNING_COLORS'; else echo "EVENING_COLORS"; fi

Or you could have PROMPT_COMMAND run an external command (which could also be a bash script or you could use a different language if you wanted) to do all the work there:

PROMPT_COMMAND=/path/to/setcolor_timeofday

The only hole I see in this is that if you have a program running when the time changes over (for example, using tail -f to watch a file), the background won't change until you return to the bash prompt.

R Samuel Klatchko
A: 

Modifying the shell foreground and background colors via PS1 in bash will be the easiest, as pointed out by others here. R Samuel Klatchko's approach with PROMPT_COMMAND is probably the most versatile. However, this has drawbacks. Bash can only use 'dull' background colors, and its foreground/background colors can be overridden by any application. Modifying your Gnome Terminal theme programmatically, especially in realtime, will be far harder, but produce much prettier results.

Sparr
@Sparr - one thing to note is that I recommended PROMPT_COMMAND, not PS1. This is important as using '0 width characters' in PS1 (or PS2, etc.) will mess up bash terminal handling. To see what I mean, try doing `export PS1='\033[42m\w\$ '` and then typing a command line that is longer then the width of the terminal.
R Samuel Klatchko