Dan, you have a good plan in mind. I can give you some feedback and hopefully someone else will add more.
In the interest of keeping this long thread right on its topic please consider opening a new thread focused on discussing the battery script.
I would change your modifications between the lines that start with
ACTION= and
BATTERY_SVG= as follows
Code: Select all
LOWBATT=15 CRITICALBATT=5 SHUTDOWN=2
LOWBATT_ACTION='batt-low.sh low'
CRITICALBATT_ACTION='batt-low.sh critical' # dr. Dan
CLICK_ACTION="Xdialog --left --title \"Battery Info\" --msgbox \"\$(cat $POWER_PATH/*/uevent | sed 's/=/: /')\" 0 0"
RIGHT_CLICK_ACTION="fatdog-power-settings.sh" # configuration GUI
[ -e /etc/battery.conf ] && . /etc/battery.conf # configuration
[ -e $FATDOG_STATE_DIR/battery.conf ] && . $FATDOG_STATE_DIR/battery.conf # user overrides --dr. Dan
This is a "standard" way to add user overrides to the system configuration.
1) Provide in-script defaults. That's
LOWBATT=15 ...
2) Read system configuration.
. /etc/battery.conf
3) Read user overrides to the system configuration.
. $FATDOG_STATE_DIR/battery.conf
I replaced ~/.config/battery_level/ with $FATDOG_STATE_DIR/ because $FATDOG_STATE_DIR is guaranteed to exist and it's where fatdog-bla-bla.sh (system) scripts normally expect to find user configuration files. This is preferred Fatdog64 usage, not policy. You can use ~/.config/some_dir even in this case, if you prefer. And you should for non-Fatdog64-system scripts. In that case I would write this stanza:
Code: Select all
USER_CONFIG=${XDG_CONFIG_HOME:-$HOME/.config}/battery_level
mkdir -p "${USER_CONFIG%/*}"
which ensures Desktop.org (XDG) compliance and creates the path if needed. On well-configured systems, you can simplify to
Code: Select all
USER_CONFIG=$HOME/.config/battery_level/battery.conf
mkdir -p "${USER_CONFIG%/*}"
I noticed several lines that follow this pattern:
Code: Select all
variable=$(cat /path/to/file | head -n 1 2>/dev/null)
This can almost always be improved to another pattern:
Code: Select all
unset variable # or set it to a default value
[ -s /path/to/file ] && read variable < /path/to/file
This code runs entirely inside the shell without starting external programs. It's faster and less error-prone.