Mini Project: Change the color of the terminal based on the time of day
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 pract开发者_JS百科ice 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: Change Gnome terminal theme programmatically
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.
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.
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.
精彩评论