From 96a34df0dbeb9b89e0a06827ee2e49cf564b4c38 Mon Sep 17 00:00:00 2001 From: Abhay Rana Date: Thu, 16 Jul 2015 20:23:09 +0530 Subject: [PATCH] scripts for fetching and setting current track for i3bar support --- cmus-current-track.sh | 37 +++++++++++++++++++++++++++++++++++++ get-current-track.sh | 3 +++ 2 files changed, 40 insertions(+) create mode 100755 cmus-current-track.sh create mode 100755 get-current-track.sh diff --git a/cmus-current-track.sh b/cmus-current-track.sh new file mode 100755 index 0000000..38bcd09 --- /dev/null +++ b/cmus-current-track.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +current_song="$HOME/.cmus/now-playing.txt" +stat="stopped" + +while [[ -n "$1" ]]; do + case "$1" in + title) title="$2" ;; + album) album="$2" ;; + artist) artist="$2" ;; + status) stat="$2" ;; + file) file="$2" ;; + url) url="$2" ;; + *) ;; + esac + shift; shift +done + +msg="" +if [[ "$stat" == "stopped" ]]; then + msg="stopped" +else + if [[ -n "$title" ]]; then + msg="$title" + else + if [[ -n "$file" ]]; then + msg=$(basename "$file") + else + msg="" + fi + fi + + [[ -n "$artist" ]] && msg="$artist / $msg" + [[ "$stat" == "paused" ]] && msg="$msg [paused]" +fi + +echo "$msg" > "$current_song" \ No newline at end of file diff --git a/get-current-track.sh b/get-current-track.sh new file mode 100755 index 0000000..6a3757f --- /dev/null +++ b/get-current-track.sh @@ -0,0 +1,3 @@ +current_song="$HOME/.cmus/now-playing.txt" + +cat $current_song \ No newline at end of file