Setting Polybar
This commit is contained in:
51
i3/.config/polybar/scripts/get_spotify_status.sh
Executable file
51
i3/.config/polybar/scripts/get_spotify_status.sh
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
|
||||
# The name of polybar bar which houses the main spotify module and the control modules.
|
||||
PARENT_BAR="now-playing"
|
||||
PARENT_BAR_PID=$(pgrep -a "polybar" | grep "$PARENT_BAR" | cut -d" " -f1)
|
||||
|
||||
# Set the source audio player here.
|
||||
# Players supporting the MPRIS spec are supported.
|
||||
# Examples: spotify, vlc, chrome, mpv and others.
|
||||
# Use `playerctld` to always detect the latest player.
|
||||
# See more here: https://github.com/altdesktop/playerctl/#selecting-players-to-control
|
||||
PLAYER="playerctld"
|
||||
|
||||
# Format of the information displayed
|
||||
# Eg. {{ artist }} - {{ album }} - {{ title }}
|
||||
# See more attributes here: https://github.com/altdesktop/playerctl/#printing-properties-and-metadata
|
||||
FORMAT="{{ title }} - {{ artist }}"
|
||||
|
||||
# Sends $2 as message to all polybar PIDs that are part of $1
|
||||
update_hooks() {
|
||||
while IFS= read -r id
|
||||
do
|
||||
polybar-msg -p "$id" hook spotify-play-pause $2 1>/dev/null 2>&1
|
||||
done < <(echo "$1")
|
||||
}
|
||||
|
||||
PLAYERCTL_STATUS=$(playerctl --player=$PLAYER status 2>/dev/null)
|
||||
EXIT_CODE=$?
|
||||
|
||||
if [ $EXIT_CODE -eq 0 ]; then
|
||||
STATUS=$PLAYERCTL_STATUS
|
||||
else
|
||||
STATUS="No player is running"
|
||||
fi
|
||||
|
||||
if [ "$1" == "--status" ]; then
|
||||
echo "$STATUS"
|
||||
else
|
||||
if [ "$STATUS" = "Stopped" ]; then
|
||||
echo "No music is playing"
|
||||
elif [ "$STATUS" = "Paused" ]; then
|
||||
update_hooks "$PARENT_BAR_PID" 2
|
||||
playerctl --player=$PLAYER metadata --format "$FORMAT"
|
||||
elif [ "$STATUS" = "No player is running" ]; then
|
||||
echo "$STATUS"
|
||||
else
|
||||
update_hooks "$PARENT_BAR_PID" 1
|
||||
playerctl --player=$PLAYER metadata --format "$FORMAT"
|
||||
fi
|
||||
fi
|
||||
|
||||
65
i3/.config/polybar/scripts/launch.sh
Normal file
65
i3/.config/polybar/scripts/launch.sh
Normal file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR="$HOME/.config/polybar"
|
||||
|
||||
get_bars () {
|
||||
find -H $DIR -name "config.ini" | xargs cat | grep -e "\[bar\/" | sort -u | sed "s/\[bar\// /g" | sed "s/.$//g"
|
||||
}
|
||||
|
||||
error () {
|
||||
cat <<- EOF
|
||||
Usage : launch.sh [bar] [theme]
|
||||
|
||||
bars (defined in any config.ini):
|
||||
EOF
|
||||
|
||||
get_bars
|
||||
|
||||
cat <<- EOF
|
||||
themes:
|
||||
rounded
|
||||
grayblocks
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Launch the bar
|
||||
launch-bar () {
|
||||
# Terminate already running bar instances
|
||||
killall -q polybar
|
||||
|
||||
if [[ -f ~/.config/bspwm/bspwmrc ]]; then
|
||||
sed -i -e "s/polybar.*/polybar\/launch\.sh $bar $style \&/g" ~/.config/bspwm/bspwmrc
|
||||
fi
|
||||
|
||||
# Wait until the processes have been shut down
|
||||
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
|
||||
|
||||
if type "xrandr"; then
|
||||
for m in $(xrandr --query | grep " connected" | cut -d" " -f1); do
|
||||
POLYBAR_MONITOR=$m polybar --reload $bar -c "$DIR"/"$style"/config.ini &
|
||||
done
|
||||
|
||||
else
|
||||
polybar --reload $bar -c "$DIR"/"$style"/config.ini &
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ "$1" = "bspwm" ]]; then
|
||||
bar="bspwm"
|
||||
elif [[ "$1" = "awesomewm" ]]; then
|
||||
bar="awesomewm"
|
||||
else
|
||||
error
|
||||
fi
|
||||
|
||||
|
||||
if [[ "$2" = "rounded" ]]; then
|
||||
style="rounded"
|
||||
launch-bar
|
||||
elif [[ "$2" = "grayblocks" ]]; then
|
||||
style="grayblocks"
|
||||
launch-bar
|
||||
else
|
||||
error
|
||||
fi
|
||||
13
i3/.config/polybar/scripts/scroll_spotify_status.sh
Executable file
13
i3/.config/polybar/scripts/scroll_spotify_status.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# see man zscroll for documentation of the following parameters
|
||||
zscroll -l 30 \
|
||||
--delay 0.1 \
|
||||
--scroll-padding " " \
|
||||
--match-command "`dirname $0`/get_spotify_status.sh --status" \
|
||||
--match-text "Playing" "--scroll 1" \
|
||||
--match-text "Paused" "--scroll 0" \
|
||||
--update-check true "`dirname $0`/get_spotify_status.sh" &
|
||||
|
||||
wait
|
||||
|
||||
Reference in New Issue
Block a user