迷你项目:根据一天中的时间更改终端的颜色
晚上好,
我对 Unix 还很陌生,所以也许这个迷你项目太过雄心勃勃。希望有人能指出正确的方向。
在小隔间里工作,我看不到外面的光线有多亮。一般来说,我在早上(阳光明媚)使用黄色终端,在 3:00 以后(夜间)使用黑色/绿色终端。
我想做的事(部分只是为了练习我的 bash)。是编写一个脚本,该脚本将在 3:00 更改我所有终端的颜色。如果这有效的话,也许我会让它们每小时改变一次或类似的事情。这样安全吗?这可能吗?
以下是我的一些规格: 索拉里斯10 bash shell Gnome
我现在正在看这个: 以编程方式更改 Gnome 终端主题
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:
Change Gnome terminal theme programmatically
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我这样做,我会从 PROMPT_COMMAND 开始。 Bash 将在显示提示之前运行该脚本。
你有几个选择。您可以在 PROMPT_COMMAND 中拥有一个脚本本身:
或者您可以让 PROMPT_COMMAND 运行一个外部命令(也可以是 bash 脚本,或者如果您愿意,您可以使用不同的语言)来完成那里的所有工作:
我看到的唯一漏洞这是因为,如果您有一个程序在时间变化时运行(例如,使用
tail -f
来查看文件),则背景不会改变,直到您返回到 bash 提示符为止。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:
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:
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.正如其他人所指出的,在 bash 中通过 PS1 修改 shell 前景色和背景色将是最简单的。 R Samuel Klatchko 的 PROMPT_COMMAND 方法可能是最通用的。然而,这有缺点。 Bash 只能使用“暗淡”背景颜色,并且其前景色/背景颜色可以被任何应用程序覆盖。以编程方式修改 Gnome 终端主题(尤其是实时修改)会困难得多,但会产生更漂亮的结果。
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.
使用 cron,它是 Unix 作业调度程序。并将其设置为运行更改 .bashrc 的命令,就像您链接的问题中一样。问题是它只适用于新终端,如果你打开了一些终端,它不会改变它们。
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.