summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorboredpasta <boredpasta@tutanota.com>2023-07-17 17:20:56 +0300
committerboredpasta <boredpasta@tutanota.com>2023-07-17 17:20:56 +0300
commit70a17dbad95de2858111c141ddbe611c075f8271 (patch)
treeb3c4d8d6c392e7179c2e9ccc0a087719a78cd345
parent93ddae21ac250ee648365771f33fa21bb24bd415 (diff)
mpc-notify: scope and cleanup variables
-rwxr-xr-xmpc-notify37
1 files changed, 21 insertions, 16 deletions
diff --git a/mpc-notify b/mpc-notify
index abf9adf..3c4604e 100755
--- a/mpc-notify
+++ b/mpc-notify
@@ -19,27 +19,19 @@
if [ -z "$WAYLAND_DISPLAY" ] && [ -z "$DISPLAY" ]; then
exit 2
fi
+
+# globals
command="$1"
+use_preview=0
-# set defaults
-# FEATURE: make width and height configurable through flags
+# defaults
+# FEATURE: make defaults configurable through flags
+preview_dir="${XDG_CONFIG_HOME:-$HOME/.config}/mpc/previews"
preview_width=64
preview_height=64
default_song_icon="media-playback-start"
-# find xdg music directory
-
-# user-dirs.dirs is not guaranteed to exist
-# shellcheck disable=SC1091
-. "${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs" 2>/dev/null || true
-xdg_music_dir="${XDG_MUSIC_DIR:-$HOME/Music}"
-
-# find mpc config directory
-mpc_config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/mpc"
-[ -d "$mpc_config_dir" ] || mkdir -p "$mpc_config_dir"
-
# issue an mpc command based on arguments and assemble notification message
-use_preview=0
case "$command" in
"")
# use defaults
@@ -101,13 +93,17 @@ case "$command" in
[ "$command" = "next" ] || [ "$command" = "prev" ] && exit
;;
esac
-song_body="$(mpc --format '[%title%[ \n%artist% - %album%]]|[%file%]' current)"
# use album preview for song icon
if [ "$use_preview" -eq 1 ]; then
- preview_dir="$mpc_config_dir/previews"
[ -d "$preview_dir" ] || mkdir -p "$preview_dir"
+ # find xdg music directory
+ # user-dirs.dirs is not guaranteed to exist
+ # shellcheck disable=SC1091
+ . "${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs" 2>/dev/null || true
+ xdg_music_dir="${XDG_MUSIC_DIR:-$HOME/Music}"
+
# get preview filename
song_filename="$(mpc --format "${xdg_music_dir}/%file%" current)"
song_album="$(mpc --format %album% current)"
@@ -140,7 +136,16 @@ if [ "$use_preview" -eq 1 ]; then
song_icon="$default_song_icon"
fi
fi
+ unset song_dirname
fi
+ unset preview_path
fi
+unset xdg_music_dir song_filename song_album
+# send the actual notification
+song_body="$(mpc --format '[%title%[ \n%artist% - %album%]]|[%file%]' current)"
notify-replace 'mpc-notify' "$song_head" "$song_body" -i "$song_icon" -u low
+
+# cleanup
+unset command preview_dir preview_width preview_height default_song_icon \
+ use_preview song_head song_body song_icon