Add system-info macOS user agent

The `system-info` directory contains scripts and configuration files to
install and remove a `launchd` user agent on macOS which collects
information about the system and outputs it to the file
`~/.cache/tmux/system-info`. This file is then read periodically by
`tmux` and the contents displayed in the status line.
This commit is contained in:
Kenneth Benzie 2021-02-16 23:55:02 +00:00
parent 1d2a5f249d
commit d96a1b7438
6 changed files with 52 additions and 5 deletions

View File

@ -27,3 +27,6 @@
dst: ~/.local/share/tmux/layouts/window-wide-left dst: ~/.local/share/tmux/layouts/window-wide-left
- src: layouts/window-wide-right - src: layouts/window-wide-right
dst: ~/.local/share/tmux/layouts/window-wide-right dst: ~/.local/share/tmux/layouts/window-wide-right
- command:
- install: system-info/install.sh
- remove: system-info/remove.sh

8
system-info/install.sh Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
script_dir=`dirname $0`
if [ `uname` = Darwin ]; then
cp $script_dir/system-info.plist ~/Library/LaunchAgents/system-info.plist
launchctl load -w ~/Library/LaunchAgents/system-info.plist
fi

6
system-info/remove.sh Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
if [ `uname` = Darwin ]; then
launchctl unload ~/Library/LaunchAgents/system-info.plist
rm ~/Library/LaunchAgents/system-info.plist
fi

View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
cache_dir=~/.cache/tmux
cache_file=$cache_dir/system-info
# Make sure the output directory exists.
if [ ! -d $cache_dir ]; then
mkdir -p $cache_dir
fi
# Cleanup cache file when interrupted.
trap '[ -f $cache_file ] && rm $cache_file; exit' INT
trap '[ -f $cache_file ] && rm $cache_file; exit' TERM
while true; do
battery="`pmset -g batt | grep --color=never -Eo '\d+%'` ↯"
echo "$battery" > $cache_file
sleep 2
done

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>system-info</string>
<key>ProgramArguments</key>
<array>
<string>/Users/benie/.config/tmux/system-info/system-info-macOS.sh</string>
</array>
<key>KeepAlive</key>
<true/>
</dict>
</plist>

View File

@ -124,11 +124,8 @@ setw -g status-left-style fg=colour240,bg=colour233
# Centre status style # Centre status style
setw -g status-style fg=colour240,bg=colour233 setw -g status-style fg=colour240,bg=colour233
# Right status style, show data and time (and battery percentage on macOS). # Right status style shows system info, date, and time.
if '[ "`uname`" = "Darwin" ]' \ setw -g status-right "#(cat ~/.cache/tmux/system-info) %a %d-%m-%y %H:%M "
'setw -g status-right "#(pmset -g batt | grep --color=never -Eo \"\\d+%%\")\
↯ %a %d-%m-%y %H:%M "' \
'setw -g status-right "%a %d-%m-%y %H:%M "'
setw -g status-right-style fg=white,bg=colour233 setw -g status-right-style fg=white,bg=colour233
# Active window status style # Active window status style