Skip to content

Commit

Permalink
Replace date with perl to fix get_time() on macOS
Browse files Browse the repository at this point in the history
The BSD date on macOS doesn't support %N. It just prints a literal N
(e.g. '1738285044.N'), which breaks the awk command in get_cache_val(),
stopping cached values from being updated.

Instead, I found this perl command at [1]. Tested on macOS, Arch Linux,
and OpenWRT (which has a minimal perl distribution. By the way, BusyBox
date doesn't support %N either but it just prints e.g. '1738285044.'
without an 'N'. So while the awk command works, [2] didn't really
improve the time precision here).

[1] https://apple.stackexchange.com/a/359718/254536
[2] https://github.com/tmux-plugins/tmux-cpu/pull/56/files#diff-e015cc3ac522b202bb23852488a7ac2c019e2c82568ecb387b97b60ebbecdf4bR72-R74
  • Loading branch information
Frederick888 committed Jan 31, 2025
1 parent bcb110d commit 544448e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ get_tmp_dir() {
}

get_time() {
date +%s.%N
perl -MTime::HiRes=time -e 'printf "%.9f\n", time'
}

get_cache_val() {
Expand Down

0 comments on commit 544448e

Please sign in to comment.