diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-04-25 15:27:17 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-04-25 15:27:17 +0900 |
| commit | 4fec7ca10c7d2262c151ffc8e2f7e6ec929c7cb8 (patch) | |
| tree | 553dbb6cd4b74aeb2c8503041b84b69461cb557b /ar | |
| parent | a9d89d3959258ff6540b0079dc014ded945c3217 (diff) | |
modified bin/dmenudelmusic
Diffstat (limited to 'ar')
| -rwxr-xr-x | ar/.local/bin/dmenudelmusic | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/ar/.local/bin/dmenudelmusic b/ar/.local/bin/dmenudelmusic index 2efbafa..91beeac 100755 --- a/ar/.local/bin/dmenudelmusic +++ b/ar/.local/bin/dmenudelmusic @@ -4,41 +4,51 @@ music_dir="${XDG_MUSIC_DIR:-${HOME}/Music}" music_txt="${music_dir}/.music.txt" playlist_dir="${XDG_CONFIG_HOME:-${HOME}/.config}/mpd/playlists" -# Using POSIX-compliant methods for file selection -selected_filename=$(find "$music_dir" -type f | awk -F/ '{print $NF}' | dmenu -i -l 20 -p "Select a file to delete:") || exit 1 +# Select the relative path (so we can find the actual file in subdirectories) +selected_relpath=$(cd "$music_dir" && find . -type f | sed 's|^\./||' | dmenu -i -l 20 -p "Select a file to delete:") || exit 1 +[ -n "$selected_relpath" ] || exit 1 -selected_file="$music_dir/$selected_filename" +selected_file="$music_dir/$selected_relpath" +selected_filename=${selected_relpath##*/} -# Extracting YouTube video ID without using -P in grep -video_id=$(strings "$selected_file" | grep 'watch?v=' | sed 's/.*watch?v=\([a-zA-Z0-9_-]*\).*/\1/' | head -1) || { +[ -f "$selected_file" ] || { + notify-send "❌ File not found: $selected_relpath" + exit 1 +} + +# Extracting YouTube video ID +video_id=$(strings "$selected_file" | grep 'watch?v=' | sed 's/.*watch?v=\([a-zA-Z0-9_-]*\).*/\1/' | head -1) +[ -n "$video_id" ] || { notify-send "❌ No YouTube video ID found in file: $selected_filename" exit 1 } -# Confirmation dialog without using echo -e -confirm=$(printf "Yes\nNo" | dmenu -i -p "Delete $selected_filename and update mpc?") +# Confirmation dialog +confirm=$(printf "Yes\nNo" | dmenu -i -p "Delete $selected_relpath and update mpc?") [ "$confirm" = "Yes" ] || { notify-send "❌ Operation cancelled." exit 0 } -# More portable sed command without -i and updating mpc -if grep -v "$video_id" "$music_txt" >"${music_txt}.tmp" && mv "${music_txt}.tmp" "$music_txt"; then - # Search and remove the filename from playlists +# Remove video_id line from .music.txt (fixed-string match) +if grep -Fv "$video_id" "$music_txt" >"${music_txt}.tmp" && mv "${music_txt}.tmp" "$music_txt"; then + # Remove the relative path from playlists (-F avoids regex pitfalls with [], (), etc.) for playlist in "$playlist_dir"/*.m3u; do [ -e "$playlist" ] || continue - if grep -q "$selected_filename" "$playlist"; then - grep -v "$selected_filename" "$playlist" > "${playlist}.tmp" && mv "${playlist}.tmp" "$playlist" - # Remove empty lines + if grep -Fq "$selected_relpath" "$playlist"; then + grep -Fv "$selected_relpath" "$playlist" > "${playlist}.tmp" && mv "${playlist}.tmp" "$playlist" sed -i '/^$/d' "$playlist" fi done - # Delete the music file - rm "$selected_file" - mpc update >/dev/null - notify-send " Success to delete:" "$selected_filename" + # Delete the actual music file + if rm "$selected_file"; then + mpc update >/dev/null + notify-send " Success to delete:" "$selected_relpath" + else + notify-send "❌ Failed to remove file: $selected_file" + fi else notify-send "❌ An error occurred." fi |
