This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/env/wm/extras/bar/modules/example.bash
2016-12-11 15:17:59 -06:00

40 lines
1.4 KiB
Bash

#!/usr/bin/env bash
source "$DOTFILES_PATH/variables.bash"
# This defines this module's priority, determining where it will be rendered on
# the bar relative to other modules.
PRIORITY=2500
# This is the trigger that the incoming line from the FIFO must match in order
# to be processed by this module.
MATCH_PREFIX="BM_EXAMPLE"
MATCH="$MATCH_PREFIX*"
# Define the function that will be called upon the match being triggered. This
# should process the first argument (the line from the FIFO) and echo the
# desired bar output.
bar_module_example() {
# Write the line from the 10th character (cutting off the MATCH_PREFIX)
echo -e "${1:10}"
}
# Export our function so that the formatter script can call it.
export -f bar_module_example
# Create a function that will periodically write to the FIFO with the correct
# prefix, thereby updating the module.
bar_module_example_updater() {
while [ $BAR_RUNNING -eq 1 ]; do
echo -e "$MATCH_PREFIX""$(date +%H.%M)" > "$BAR_FIFO"
sleep 30
done
}
export -f bar_module_example_updater
# Optional: Initialize that module by immediately writing to the FIFO using your
# prefix to show some default information on the bar when it loads.
echo -e "$MATCH_PREFIX"Loading... > "$BAR_FIFO"
# Register our module so that it is started once the bar is ready
register_bar_module "$PRIORITY" "$MATCH" "bar_module_example" "bar_module_example_updater"