Original link: https://blog.lilydjwg.me/posts/216425.html
This article is from Evian’s Blog , please indicate when reprinting.
In the status bar of tmux, the current time is usually displayed. It is also very simple to configure, just throw a time format string like %Y-%m-%d %H:%M:%S
in the past. However, there is a small problem with this: the time is only accurate to the second. I don’t mean that I want it to display milliseconds, but I want it to display (broadcast) “12:00:00” just like the time on TV and radio stations, which happens to be the beginning of that second.
Generally speaking, such a delay of a random number within a second is not a problem, except when you have multiple such timestamps –
It is completely uncertain which of these timestamps will be updated first and which will be updated later. You may see that the server on the other side of the world arrives first for a certain second, and then the local can keep up. Even in different clients of the same tmux, the update time of this timestamp may be different.
Another reason I want to optimize this is that I often use extrace to see the command line parameters used by a program to call another program, but how many tmux I connect locally, how many sh + awk processes will come out to read the system every second load. Especially after I switched from Awesome to Wayfire, the top bar was changed to waybar. Many indicators are built-in or external scripts written by myself. It is no longer necessary to run a subprocess every few seconds to obtain information, so that tmux calls the subprocess. The interference caused by the refresh state is highlighted.
So there is the accurate-time program. It reads the system load every full second and sends it to tmux along with the current time to display. One process per second is a lot less.
Since my program reads the load by itself, it is convenient to do more things, such as using different text colors according to the load situation: green means low load, gray and white means a little bit of work, blue and cyan are busy, yellow , Magenta means that you are too busy, and red means you are tired. I accidentally discovered that the qemu-git package uses ninja, but a layer of make was applied when linking, which caused the system load to reach more than 200. But no matter how high or low, the load display of tmux is red, so I may have turned a blind eye many times before. With the addition of color, such anomalies are easier to notice. In the past, I found that the system load was high every time the fan was whirling locally, but if I used headphones, I couldn’t hear it, and now there is an indication of high load.
Installation and configuration are very simple, cargo build --release
compile, then throw the compiled target/release/accurate-time
into $PATH
, and then configure the right side of the tmux status bar as follows:
if-shell "accurate-time tmux" { set -g status-interval 0 } { set -g status-interval 1 set -g status-right "#[fg=red]#(awk '{print $1, $2, $3}' /proc/loadavg) #[fg=colour15]%Y-%m-%d %H:%M :%S" }
Originally, I planned to do the same for the time on the waybar, but after writing the program, I found that the waybar itself has aligned the time to the update interval.
This article is reproduced from: https://blog.lilydjwg.me/posts/216425.html
This site is for inclusion only, and the copyright belongs to the original author.