summaryrefslogtreecommitdiff
path: root/ar/.local/bin/dmenudelmusic
diff options
context:
space:
mode:
Diffstat (limited to 'ar/.local/bin/dmenudelmusic')
-rwxr-xr-xar/.local/bin/dmenudelmusic14
1 files changed, 10 insertions, 4 deletions
diff --git a/ar/.local/bin/dmenudelmusic b/ar/.local/bin/dmenudelmusic
index fce8db2..c28130a 100755
--- a/ar/.local/bin/dmenudelmusic
+++ b/ar/.local/bin/dmenudelmusic
@@ -8,7 +8,7 @@ playlist_dir="${XDG_CONFIG_HOME:-${HOME}/.config}/mpd/playlists"
# Select the relative path. Sort the list so "first match" semantics in dmenu
# are deterministic — otherwise filesystem order is unstable and typing a
-# substring (e.g. "성시경") can return whichever file find walked first.
+# substring can return whichever file find walked first.
# `-not -path '*/.*'` skips hidden files (.music.txt, etc.); name filter limits to audio.
selected_relpath=$(cd "$music_dir" && find . -type f -not -path '*/.*' \( -name '*.mp3' -o -name '*.m4a' -o -name '*.opus' -o -name '*.flac' -o -name '*.wav' -o -name '*.webm' \) | sed 's|^\./||' | LC_ALL=C.UTF-8 sort | dmenu -i -l 20 -p "Select a file to delete:") || exit 1
[ -n "$selected_relpath" ] || exit 1
@@ -45,12 +45,18 @@ remove_id_from() {
}
if remove_id_from "$music_txt" && remove_id_from "$music_titles"; then
- # Remove the relative path from playlists (-F avoids regex pitfalls with [], (), etc.)
+ # Remove the relative path from every playlist (entire.m3u + genre lists like
+ # jpop/kpop/pop). -F avoids regex pitfalls with [], (), etc.
+ # These .m3u files are symlinks into the dotfiles repo, so write the result
+ # back with `cat > "$playlist"` (which follows the symlink) instead of
+ # `mv`/`sed -i`, both of which would replace the symlink with a plain file.
for playlist in "$playlist_dir"/*.m3u; do
[ -e "$playlist" ] || continue
if grep -Fq "$selected_relpath" "$playlist"; then
- grep -Fv "$selected_relpath" "$playlist" > "${playlist}.tmp" && mv "${playlist}.tmp" "$playlist"
- sed -i '/^$/d' "$playlist"
+ _pl_tmp="$(mktemp)" || continue
+ grep -Fv "$selected_relpath" "$playlist" | sed '/^$/d' > "$_pl_tmp"
+ cat "$_pl_tmp" > "$playlist"
+ rm -f "$_pl_tmp"
fi
done