Minor code refinements

Clean up some parts of the code without affecting each script's
functionality.  Improve the documentation.
This commit is contained in:
Protesilaos Stavrou 2019-04-29 12:43:30 +03:00
parent bd61083e8b
commit b229596ca5
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA
2 changed files with 36 additions and 15 deletions

View file

@ -21,32 +21,39 @@
# Assign this executable to a key binding for your convenience. This
# file is part of my dotfiles: https://gitlab.com/protesilaos/dotfiles
#
# Dependency for sending desktop notifications:
# Debian buster dependency for sending desktop notifications:
# apt install libnotify-bin
#
# Optional dependency to display album art:
# Optional dependencies to display album art:
# apt install playerctl mpDris2
# Fetch album art information using playerctl, if it is installed. Else
# display generic icon.
if [ "$(command -v playerctl 2> /dev/null)" ]; then
# TODO use paramater expansion instead of sed
album_art=$(playerctl metadata 'mpris:artUrl' --player=mpd | sed 's,file://,,')
else
# else use the "rhythmbox" icon from the available icon theme
album_art='rhythmbox'
fi
# The square brackets are meant to display their content only if the
# included metatag is available. This is documented in `man mpc`.
mpc_format="$(mpc --format '%artist% - %title%\n%album%[ (%date%)]' current)"
# This script accepts "cli" as a single argument, in which case it
# prints the notification to the terminal (stdout). Otherwise it sends
# a desktop notification (if the dependency is already installed).
if [ "$1" == "cli" ]; then
echo -e "$(mpc --format '%artist% - %title%\\n%album% (%date%)' current)"\\n"Album art: $album_art"
echo "$mpc_format"
echo "Album art: $album_art"
else
if [ "$(command -v notify-send 2> /dev/null)" ]; then
notify-send -i "$album_art" "Now Playing" "$(mpc --format '%artist% - %title%\\n%album% (%date%)' current)"
notify-send -i "$album_art" "Now Playing" "$mpc_format"
else
echo -e "ERROR. Missing dependency 'libnotify-bin'.\
\\nThis is the package that provides the 'notify-send' command.\
\\nCannot send message to the notification daemon without it."
echo "ERROR. Missing Debian buster dependency 'libnotify-bin'"
echo "Cannot send desktop notification"
echo "Aborting"
exit 1
fi
fi

View file

@ -44,24 +44,38 @@
# General variables {{{
# ---------------------
# Array with all available tempus themes. The `sed` command cleans up
# the output, stripping it of surrounding text. As for `sort`, it just
# presents the output in alphabetical order.
tempus_themes_array=$(find "$HOME/.local/share/my_colours/shell/" -type f -printf "%f\\n" | sed -e 's/tempus_\([a-z]*\).sh/\1/g' | sort)
# We use this logic to check and then pass to the rest of the script the
# colour values and the custom font. If the files are not available,
# the script exits with an error.
source_file() {
if [ -f "$1" ]; then
source "$1"
else
echo "ERROR: Could not find active $2"
echo "Aborting"
exit 1
fi
}
# Pass custom colours to the `dmenu` command. These will style the
# background and foreground values using shell variables. That file is
# used in other places as well to offer a convenient way of styling
# multiple tools in a that is centralised and straightforward.
# TODO make this conditional
source "$HOME/.local/share/my_colours/active-tempus-theme.sh"
my_colours="$HOME/.local/share/my_colours/active-tempus-theme.sh"
source_file "$my_colours" 'Tempus theme'
# Get the system-wide custom font. This is done with other `dmenu`
# scripts as well to provide for an easy way to style them all at once.
# The actual font is a `fontconfig` alias. See my dotfiles under
# "fontconfig".
# TODO make this conditional
source "$HOME/.local/share/my_custom_ui_font.sh"
my_font="$HOME/.local/share/my_custom_ui_font.sh"
source_file "$my_font" 'UI font'
# TODO use parameter expansion instead of sed
# Array with all available tempus themes. The `sed` command cleans up
# the output, stripping it of surrounding text. As for `sort`, it just
# presents the output in alphabetical order.
tempus_themes_array=$(find "$HOME/.local/share/my_colours/shell/" -type f -printf "%f\\n" | sed -e 's/tempus_\([a-z]*\).sh/\1/g' | sort)
# }}}