2022-05-29 19:29:10 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-06-08 21:23:51 +02:00
|
|
|
# cmus-track
|
2022-05-29 19:29:10 +02:00
|
|
|
#
|
2022-06-08 21:23:51 +02:00
|
|
|
# cmus track control for moving or removing the current track.
|
2022-05-29 19:29:10 +02:00
|
|
|
#
|
|
|
|
# Usage:
|
2022-06-08 21:23:51 +02:00
|
|
|
# cmus-track rm # will also switch to the next track
|
2022-05-29 19:29:10 +02:00
|
|
|
# cmus-track mv path/to/new/dir
|
|
|
|
#
|
|
|
|
|
|
|
|
function get_field() {
|
|
|
|
local row
|
|
|
|
row="$(grep "^$1 " <<<"$QUERY_RESULT")"
|
|
|
|
echo "${row#"$1 "}"
|
|
|
|
}
|
|
|
|
|
|
|
|
QUERY_RESULT="$(cmus-remote --query 2>/dev/null)"
|
|
|
|
[ -z "$QUERY_RESULT" ] && exit 1
|
|
|
|
|
|
|
|
FILE="$(get_field file)"
|
|
|
|
|
|
|
|
ACTION="$1"
|
|
|
|
if [ "$ACTION" == "rm" ]; then
|
2022-06-03 20:25:27 +02:00
|
|
|
trash -v "$FILE"
|
2022-05-29 19:29:10 +02:00
|
|
|
cmus-remote --next
|
|
|
|
elif [ "$ACTION" == "mv" ]; then
|
|
|
|
TARGET_DIR="${2}"
|
|
|
|
if ! [ -d "$TARGET_DIR" ]; then
|
|
|
|
echo "ERROR: TARGET_DIR doesn't exist: '$TARGET_DIR'." 1>&2
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
|
|
|
|
mv -iv "$FILE" "$TARGET_DIR" || exit 4
|
|
|
|
else
|
|
|
|
echo "ERROR: Unsupported action '$ACTION'." 1>&2
|
|
|
|
exit 2
|
|
|
|
fi
|