dotfiles/.local/bin/cmus-track

39 lines
796 B
Bash
Executable File

#!/bin/bash
# cmus-track
#
# cmus track control for moving or removing the current track.
#
# Usage:
# cmus-track rm # will also switch to the next track
# 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
trash -v "$FILE"
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