Skip to content

Commit 34588b0

Browse files
IngoMeyer441erikw
authored andcommitted
Add support for playerctl in the now_playing segment
1 parent 6610af4 commit 34588b0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

segments/now_playing.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ TMUX_POWERLINE_SEG_NOW_PLAYING_MPD_HOST_DEFAULT="localhost"
99
TMUX_POWERLINE_SEG_NOW_PLAYING_MPD_PORT_DEFAULT="6600"
1010
TMUX_POWERLINE_SEG_NOW_PLAYING_LASTFM_UPDATE_PERIOD_DEFAULT="30"
1111
TMUX_POWERLINE_SEG_NOW_PLAYING_MPD_SIMPLE_FORMAT_DEFAULT="%artist% - %title%"
12+
TMUX_POWERLINE_SEG_NOW_PLAYING_PLAYERCTL_FORMAT_DEFAULT="{{ artist }} - {{ title }}"
1213
TMUX_POWERLINE_SEG_NOW_PLAYING_RHYTHMBOX_FORMAT_DEFAULT="%aa - %tt"
1314
TMUX_POWERLINE_SEG_NOW_PLAYING_NOTE_CHAR_DEFAULT=""
1415

1516
generate_segmentrc() {
1617
read -d '' rccontents << EORC
17-
# Music player to use. Can be any of {audacious, banshee, cmus, itunes, lastfm, mocp, mpd, mpd_simple, pithos, rdio, rhythmbox, spotify, spotify_wine, file}.
18+
# Music player to use. Can be any of {audacious, banshee, cmus, itunes, lastfm, mocp, mpd, mpd_simple, pithos, playerctl, rdio, rhythmbox, spotify, spotify_wine, file}.
1819
export TMUX_POWERLINE_SEG_NOW_PLAYING_MUSIC_PLAYER=""
1920
# File to be read in case the song is being read from a file
2021
export TMUX_POWERLINE_SEG_NOW_PLAYING_FILE_NAME=""
@@ -31,6 +32,8 @@ export TMUX_POWERLINE_SEG_NOW_PLAYING_MPD_HOST="${TMUX_POWERLINE_SEG_NOW_PLAYING
3132
export TMUX_POWERLINE_SEG_NOW_PLAYING_MPD_PORT="${TMUX_POWERLINE_SEG_NOW_PLAYING_MPD_PORT_DEFAULT}"
3233
# Song display format for mpd_simple. See mpc(1) for delimiters.
3334
export TMUX_POWERLINE_SEG_NOW_PLAYING_MPD_SIMPLE_FORMAT="${TMUX_POWERLINE_SEG_NOW_PLAYING_MPD_SIMPLE_FORMAT_DEFAULT}"
35+
# Song display format for playerctl. see "Format Strings" in playerctl(1).
36+
export TMUX_POWERLINE_SEG_NOW_PLAYING_PLAYERCTL_FORMAT="${TMUX_POWERLINE_SEG_NOW_PLAYING_PLAYERCTL_FORMAT_DEFAULT}"
3437
# Song display format for rhythmbox. see "FORMATS" in rhythmbox-client(1).
3538
export TMUX_POWERLINE_SEG_NOW_PLAYING_RHYTHMBOX_FORMAT="${TMUX_POWERLINE_SEG_NOW_PLAYING_RHYTHMBOX_FORMAT_DEFAULT}"
3639
@@ -66,6 +69,7 @@ run_segment() {
6669
"mpd_simple") np=$(__np_mpd_simple) ;;
6770
"pithos") np=$(__np_pithos) ;;
6871
"rdio") np=$(__np_rdio) ;;
72+
"playerctl") np=$(__np_playerctl) ;;
6973
"rhythmbox") np=$(__np_rhythmbox) ;;
7074
"spotify") np=$(__np_spotify) ;;
7175
"file") np=$(__np_file) ;;
@@ -121,8 +125,11 @@ __process_settings() {
121125
if [ -z "$TMUX_POWERLINE_SEG_NOW_PLAYING_NOTE_CHAR" ]; then
122126
export TMUX_POWERLINE_SEG_NOW_PLAYING_NOTE_CHAR="${TMUX_POWERLINE_SEG_NOW_PLAYING_NOTE_CHAR_DEFAULT}"
123127
fi
128+
if [ -z "$TMUX_POWERLINE_SEG_NOW_PLAYING_PLAYERCTL_FORMAT" ]; then
129+
export TMUX_POWERLINE_SEG_NOW_PLAYING_PLAYERCTL_FORMAT="${TMUX_POWERLINE_SEG_NOW_PLAYING_PLAYERCTL_FORMAT_DEFAULT}"
130+
fi;
124131
if [ -z "$TMUX_POWERLINE_SEG_NOW_PLAYING_RHYTHMBOX_FORMAT" ]; then
125-
export TMUX_POWERLINE_SEG_NOW_PLAYING_RHYTHMBOX_FORMAT="${TMUX_POWERLINE_SEG_NOW_PLAYING_RHYTHMBOX_FORMAT}"
132+
export TMUX_POWERLINE_SEG_NOW_PLAYING_RHYTHMBOX_FORMAT="${TMUX_POWERLINE_SEG_NOW_PLAYING_RHYTHMBOX_FORMAT_DEFAULT}"
126133
fi;
127134
}
128135

@@ -268,6 +275,13 @@ __np_rhythmbox() {
268275
fi
269276
}
270277

278+
__np_playerctl() {
279+
if [ "$(playerctl status)" = "Playing" ]; then
280+
np=$(playerctl metadata --format="$TMUX_POWERLINE_SEG_NOW_PLAYING_PLAYERCTL_FORMAT")
281+
echo "$np"
282+
fi
283+
}
284+
271285
__np_spotify() {
272286
if shell_is_linux; then
273287
metadata=$(dbus-send --reply-timeout=42 --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' 2>/dev/null)

0 commit comments

Comments
 (0)