From efa55b28b0887c7bc5b08a4d7dc688cc4c475178 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 26 Oct 2016 15:18:11 +1100 Subject: [PATCH 1/5] Rewrite getsong --- neofetch | 135 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 74 insertions(+), 61 deletions(-) diff --git a/neofetch b/neofetch index d3350931..dd03065b 100755 --- a/neofetch +++ b/neofetch @@ -1120,79 +1120,92 @@ getmemory() { # Song {{{ getsong() { - if mpc version >/dev/null 2>&1; then - song="$(mpc current 2>/dev/null)" - state="$(mpc | awk -F '\\[|\\]' '/\[/ {printf $2}' 2>/dev/null)" + player="$(ps x | awk '!(/awk|Helper|Cache/) && /mpd|cmus|mocp|spotify|Google Play|iTunes.app|rhythmbox|banshee|amarok|deadbeef|audacious/ {printf $5 " " $6; exit}')" - elif [ -n "$(ps x | awk '!(/awk/) && /cmus/')" ]; then - IFS=$'\n' - song=($(cmus-remote -Q | grep "tag artist \|tag title \|status" 2>/dev/null | sort)) - state="${song[0]/status }" - artist="${song[1]/tag artist }" - title="${song[2]/tag title }" - song="${artist/tag title } - ${title/tag artist }" + case "$player" in + "mpd"*) + song="$(mpc current 2>/dev/null)" + state="$(mpc | awk -F '\\[|\\]' '/\[/ {printf $2}' 2>/dev/null)" + ;; - elif pgrep "mocp" >/dev/null 2>&1; then - song="$(mocp -Q "%artist - %song" 2>/dev/null)" - state="$(mocp -Q "%state" 2>/dev/null)" + "cmus"*) + IFS=$'\n' + song=($(cmus-remote -Q | grep "tag artist \|tag title \|status" 2>/dev/null | sort)) + state="${song[0]/status }" + artist="${song[1]/tag artist }" + title="${song[2]/tag title }" + song="${artist/tag title } - ${title/tag artist }" + ;; - elif [ -n "$(ps x | awk '!(/awk/) && /spotify/')" ]; then - case "$os" in - "Linux") - # This command is way too long - song="$(\ - dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 \ - org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' |\ - awk -F 'string "' '/string|array/ {printf "%s",$2; next}{print ""}' |\ - awk -F '"' '/artist|title/ {printf $2 " - "}' - )" - song="${song% - }" - song="${song/'('*}" - song="${song//'['*}" - ;; + "mocp"*) + song="$(mocp -Q "%artist - %song" 2>/dev/null)" + state="$(mocp -Q "%state" 2>/dev/null)" + ;; - "Mac OS X") - song="$(osascript -e 'tell application "Spotify" to artist of current track as string & " - " & name of current track as string')" - state="$(osascript -e 'tell application "Spotify" to player state as string')" - ;; - esac + "spotify"*) + case "$os" in + "Linux") + # Thanks dbus + song="$(\ + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 \ + org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' |\ + awk -F 'string "' '/string|array/ {printf "%s",$2; next}{print ""}' |\ + awk -F '"' '/artist|title/ {printf $2 " - "}' + )" + song="${song% - }" + song="${song/'('*}" + song="${song//'['*}" + ;; - elif [ -n "$(ps x | awk '!(/awk/ || /Helper/) && /Google Play Music Desktop Player/')" ] && type -p gpmdp-remote >/dev/null 2>&1; then - song="$(gpmdp-remote current)" - state="$(gpmdp-remote status)" + "Mac OS X") + song="$(osascript -e 'tell application "Spotify" to artist of current track as string & " - " & name of current track as string')" + state="$(osascript -e 'tell application "Spotify" to player state as string')" + ;; + esac + ;; - elif [ -n "$(ps x | awk '!(/awk/ || /Helper/ || /Cache/) && /iTunes.app/')" ]; then - song="$(osascript -e 'tell application "iTunes" to artist of current track as string & " - " & name of current track as string')" - state="$(osascript -e 'tell application "iTunes" to player state as string')" + "google play"*) + song="$(gpmdp-remote current 2>/dev/null)" + state="$(gpmdp-remote status 2>/dev/null)" + ;; - elif [ -n "$(ps x | awk '!(/awk/) && /rhythmbox/')" ]; then - song="$(rhythmbox-client --print-playing)" - # Well, what can you expect? It's dbus after all. - state="$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 \ - org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string: 'PlayBackStatus' |\ - awk -F 'string "' '{printf $2}')" - state="${state//\"}" + "itunes.app"*) + song="$(osascript -e 'tell application "iTunes" to artist of current track as string & " - " & name of current track as string')" + state="$(osascript -e 'tell application "iTunes" to player state as string')" + ;; - elif [ -n "$(ps x | awk '!(/awk/) && /banshee/')" ]; then - artist="$(banshee --query-artist | awk -F':' '{print $2}')" - title="$(banshee --query-title | awk -F':' '{print $2}')" - song="$artist - $title" - state="$(banshee --query-current-state | awk -F':' '{print $2}')" + "rhythmbox"*) + song="$(rhythmbox-client --print-playing)" + # Well, what can you expect? It's dbus after all. + state="$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 \ + org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string: 'PlayBackStatus' |\ + awk -F 'string "' '{printf $2}')" + state="${state//\"}" + ;; - elif [ -n "$(ps x | awk '!(/awk/) && /amarok/')" ]; then - artist="$(qdbus org.kde.amarok /Player GetMetadata | awk -F':' '/^artist/ {print $2}')" - title="$(qdbus org.kde.amarok /Player GetMetadata | awk -F':' '/title/ {print $2}')" - song="$artist - $title" + "banshee"*) + artist="$(banshee --query-artist | awk -F':' '{print $2}')" + title="$(banshee --query-title | awk -F':' '{print $2}')" + song="$artist - $title" + state="$(banshee --query-current-state | awk -F':' '{print $2}')" + ;; - elif [ -n "$(ps x | awk '!(/awk/) && /deadbeef/')" ]; then - song="$(deadbeef --nowplaying '%a - %t')" + "amarok"*) + artist="$(qdbus org.kde.amarok /Player GetMetadata | awk -F':' '/^artist/ {print $2}')" + title="$(qdbus org.kde.amarok /Player GetMetadata | awk -F':' '/title/ {print $2}')" + song="$artist - $title" + ;; - elif [ -n "$(ps x | awk '!(/awk/) && /audacious/')" ]; then - song="$(audtool current-song)" + "deadbeef"*) + song="$(deadbeef --nowplaying '%a - %t')" + ;; - else - song="Not Playing" - fi + "audacious"*) + song="$(audtool current-song)" + ;; + + *) song="Not Playing" ;; + esac case "$state" in "paused" | "PAUSE" | "Paused") From 0c41c285a76e068f7632cfe1e31c3486368a4252 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 26 Oct 2016 18:09:59 +1100 Subject: [PATCH 2/5] Fix processes with paths in name' --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index dd03065b..99b0e665 100755 --- a/neofetch +++ b/neofetch @@ -1122,7 +1122,7 @@ getmemory() { getsong() { player="$(ps x | awk '!(/awk|Helper|Cache/) && /mpd|cmus|mocp|spotify|Google Play|iTunes.app|rhythmbox|banshee|amarok|deadbeef|audacious/ {printf $5 " " $6; exit}')" - case "$player" in + case "${player/*\/}" in "mpd"*) song="$(mpc current 2>/dev/null)" state="$(mpc | awk -F '\\[|\\]' '/\[/ {printf $2}' 2>/dev/null)" From 43ac9dfcb247a6f0233de03fa647af4f7e16dfa2 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 26 Oct 2016 18:22:08 +1100 Subject: [PATCH 3/5] Docs --- neofetch | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 99b0e665..f133a273 100755 --- a/neofetch +++ b/neofetch @@ -1120,6 +1120,7 @@ getmemory() { # Song {{{ getsong() { + # This is absurdly long. player="$(ps x | awk '!(/awk|Helper|Cache/) && /mpd|cmus|mocp|spotify|Google Play|iTunes.app|rhythmbox|banshee|amarok|deadbeef|audacious/ {printf $5 " " $6; exit}')" case "${player/*\/}" in @@ -1176,7 +1177,7 @@ getsong() { "rhythmbox"*) song="$(rhythmbox-client --print-playing)" - # Well, what can you expect? It's dbus after all. + # Thanks dbus state="$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 \ org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string: 'PlayBackStatus' |\ awk -F 'string "' '{printf $2}')" From 9889ba14cbc938162ba4036a2e2ee4451f5f1dcd Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 26 Oct 2016 21:04:58 +1100 Subject: [PATCH 4/5] Song: Fix iTunes --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index f133a273..b9bb8986 100755 --- a/neofetch +++ b/neofetch @@ -1121,7 +1121,7 @@ getmemory() { getsong() { # This is absurdly long. - player="$(ps x | awk '!(/awk|Helper|Cache/) && /mpd|cmus|mocp|spotify|Google Play|iTunes.app|rhythmbox|banshee|amarok|deadbeef|audacious/ {printf $5 " " $6; exit}')" + player="$(ps x | awk '!(/awk|Helper|Cache/) && /mpd|cmus|mocp|spotify|Google Play|iTunes|rhythmbox|banshee|amarok|deadbeef|audacious/ {printf $5 " " $6; exit}')" case "${player/*\/}" in "mpd"*) From 6f41167eb5034d211ee17ca6625dd6b973e14596 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 26 Oct 2016 21:18:46 +1100 Subject: [PATCH 5/5] Song: Fix iTunes 2 --- neofetch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index b9bb8986..6cb7e3bf 100755 --- a/neofetch +++ b/neofetch @@ -1121,7 +1121,7 @@ getmemory() { getsong() { # This is absurdly long. - player="$(ps x | awk '!(/awk|Helper|Cache/) && /mpd|cmus|mocp|spotify|Google Play|iTunes|rhythmbox|banshee|amarok|deadbeef|audacious/ {printf $5 " " $6; exit}')" + player="$(ps x | awk '!(/awk|Helper|Cache/) && /mpd|cmus|mocp|spotify|Google Play|iTunes.app|rhythmbox|banshee|amarok|deadbeef|audacious/ {printf $5 " " $6; exit}')" case "${player/*\/}" in "mpd"*) @@ -1170,7 +1170,7 @@ getsong() { state="$(gpmdp-remote status 2>/dev/null)" ;; - "itunes.app"*) + "itunes"*) song="$(osascript -e 'tell application "iTunes" to artist of current track as string & " - " & name of current track as string')" state="$(osascript -e 'tell application "iTunes" to player state as string')" ;;