mirror of https://github.com/polybar/polybar.git
remove scripts, they are moved to polybar-scripts, add new text
parent
ec40d1d2b2
commit
50e7c0bc15
|
@ -1,563 +1,8 @@
|
|||
## Attention :)
|
||||
We have started to maintain a repository for scripts contributed by the community: [polybar-scripts](https://github.com/x70b1/polybar-scripts).
|
||||
|
||||
We have started to maintain a repository for user contributed scripts: [polybar-scripts](https://github.com/x70b1/polybar-scripts)
|
||||
This means that everything written in Shell, Python or Perl is collected there. Look over there!
|
||||
|
||||
The scripts on this page will be copied one by one. If you want to help or add a new script, send a pull request.
|
||||
|
||||
***
|
||||
|
||||
|
||||
This is a list of modules written by polybar users. They can be added to the bar using a [`custom/script`](https://github.com/jaagr/polybar/wiki/Module:-script) module.
|
||||
|
||||
**Disclaimer:** These scripts are not tested by the polybar developers, use them at your own risk.
|
||||
|
||||
# Contents
|
||||
- [Music Player - Basic track info (MPRIS)](#music-player---basic-track-info-mpris)
|
||||
- [Qmmp - info & control](#qmmp---info--control)
|
||||
- [Pomodoro](#pomodoro-timer)
|
||||
- [Trash](#trash)
|
||||
- [pulseaudio volume](#pulseaudio-volume)
|
||||
- [moc - info & control](#moc---info--control)
|
||||
- [cmus](#cmus)
|
||||
- [mpv](#mpv)
|
||||
----------------------------------------
|
||||
|
||||
# Music Player - Basic track info (MPRIS)
|
||||
![mpris](http://i.imgur.com/3W0zAtq.png)
|
||||
|
||||
## Dependencies
|
||||
* [aur: ttf-font-awesome](https://aur.archlinux.org/packages/ttf-font-awesome/)
|
||||
* [playerctl](https://github.com/acrisci/playerctl)
|
||||
|
||||
## Setup
|
||||
* Create `~/.config/polybar/mpris.sh` script
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
# Specifying the icon(s) in the script
|
||||
# This allows us to change its appearance conditionally
|
||||
icon=""
|
||||
|
||||
player_status=$(playerctl status 2> /dev/null)
|
||||
if [[ $? -eq 0 ]]; then
|
||||
metadata="$(playerctl metadata artist) - $(playerctl metadata title)"
|
||||
fi
|
||||
|
||||
# Foreground color formatting tags are optional
|
||||
if [[ $player_status = "Playing" ]]; then
|
||||
echo "%{F#D08770}$icon $metadata" # Orange when playing
|
||||
elif [[ $player_status = "Paused" ]]; then
|
||||
echo "%{F#65737E}$icon $metadata" # Greyed out info when paused
|
||||
else
|
||||
echo "%{F#65737E}$icon" # Greyed out icon when stopped
|
||||
fi
|
||||
```
|
||||
|
||||
## Module
|
||||
```ini
|
||||
[module/music]
|
||||
type = custom/script
|
||||
interval = 2
|
||||
|
||||
label = %output:0:45:...%
|
||||
exec = ~/.config/polybar/mpris.sh
|
||||
click-left = playerctl previous
|
||||
click-middle = playerctl play-pause
|
||||
click-right = playerctl next
|
||||
```
|
||||
|
||||
----------------------------------------
|
||||
|
||||
# qmmp - info & control
|
||||
![qmmp](http://i.imgur.com/KBfpCYT.png)
|
||||
|
||||
## Setup
|
||||
* Create `~/.config/polybar/qmmp.sh` script
|
||||
```bash
|
||||
#!/bin/bash
|
||||
status=`qmmp --nowplaying '%p - %t'`
|
||||
if [[ $status == "-" ]]
|
||||
then
|
||||
echo "Stopped"
|
||||
else
|
||||
echo "$status"
|
||||
fi
|
||||
```
|
||||
|
||||
## Module
|
||||
```ini
|
||||
[module/qmmp]
|
||||
type = custom/script
|
||||
exec = ~/.config/polybar/qmmp.sh
|
||||
exec-if = pgrep -x qmmp
|
||||
click-left = qmmp -t
|
||||
click-right = qmmp --next
|
||||
interval = 5
|
||||
```
|
||||
|
||||
----------------------------------------
|
||||
|
||||
# Pomodoro timer
|
||||
![pomodoro_running](https://i.imgur.com/Ruyo7ZL.png)
|
||||
|
||||
## Dependencies
|
||||
* [aur:pymodoro-git](https://aur.archlinux.org/packages/pymodoro-git/)
|
||||
* [aur:nerd-fonts-complete](https://aur.archlinux.org/packages/nerd-fonts-complete/) Optional to get nice looking glyphs
|
||||
|
||||
## Setup
|
||||
* Modify the following module to your needs, the command line parameters for the exec line can be found in pymodoro repo
|
||||
* Change the icons to your needs (the commented exec uses the pomicons glyphs as in the Nerd fonts collection)
|
||||
|
||||
## Module
|
||||
```ini
|
||||
[module/pomodoro]
|
||||
type = custom/script
|
||||
; Use pomodoro glyphs in Nerd fonts
|
||||
; exec = pymodoro --break-prefix " " --pomodoro-prefix " " --pomodoro --empty --break --length 5
|
||||
; Use default symbols
|
||||
exec = pymodoro --length 5
|
||||
label = %output%
|
||||
tail = true
|
||||
interval = 0
|
||||
; Start or reset the timer
|
||||
click-left = if [ -e ~/.pomodoro_session ]; then rm ~/.pomodoro_session; else echo "25 5" > ~/.pomodoro_session; fi
|
||||
; Increase pomodoro time
|
||||
click-right = echo "$((`cut .pomodoro_session -d ' ' -f 1`+5)) 5" > .pomodoro_session
|
||||
; Reduce pomodoro time
|
||||
click-middle = echo "$((`cut .pomodoro_session -d ' ' -f 1`-5)) 5" > .pomodoro_session
|
||||
```
|
||||
## Usage
|
||||
* Left click starts or stops/resets the timer
|
||||
* Right click increases the pomodoro time by 5 minutes
|
||||
* Middle click decreases the pomodoro time by 5 minutes
|
||||
|
||||
----------------------------------------
|
||||
|
||||
# Trash
|
||||
![trash](http://i.imgur.com/meMb27p.png)
|
||||
|
||||
## Dependencies
|
||||
* Sound event "trash-empty.oga" (if want)
|
||||
* [aur: ttf-font-awesome](https://aur.archlinux.org/packages/ttf-font-awesome/)
|
||||
|
||||
## Setup
|
||||
* Create `~/.config/polybar/trash` script
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
TRASH_DIRECTORY="${BLOCK_INSTANCE}"
|
||||
|
||||
if [[ "${TRASH_DIRECTORY}" = "" ]]; then
|
||||
TRASH_DIRECTORY="${XDG_DATA_HOME:-${HOME}/.local/share}/Trash"
|
||||
fi
|
||||
|
||||
# Left click
|
||||
if [[ "${BLOCK_BUTTON}" -eq 1 ]]; then
|
||||
xdg-open "${TRASH_DIRECTORY}/files"
|
||||
# Right click
|
||||
elif [[ "${BLOCK_BUTTON}" -eq 3 ]]; then
|
||||
# Delete all files permanently (unlink them)
|
||||
rm -r "${TRASH_DIRECTORY}/files"
|
||||
rm -r "${TRASH_DIRECTORY}/info"
|
||||
exec paplay ~/.sounds/freedesktop/stereo/trash-empty.oga
|
||||
# Create new directory
|
||||
mkdir "${TRASH_DIRECTORY}/files"
|
||||
mkdir "${TRASH_DIRECTORY}/info"
|
||||
fi
|
||||
|
||||
TRASH_COUNT=$(ls -U -1 "${TRASH_DIRECTORY}/files" | wc -l)
|
||||
|
||||
URGENT_VALUE=30
|
||||
|
||||
echo "${TRASH_COUNT}"
|
||||
echo "${TRASH_COUNT}"
|
||||
echo ""
|
||||
|
||||
if [[ "${TRASH_COUNT}" -ge "${URGENT_VALUE}" ]]; then
|
||||
exit 31
|
||||
fi
|
||||
```
|
||||
|
||||
## Module
|
||||
```ini
|
||||
[module/trash]
|
||||
interval = 1
|
||||
type = custom/script
|
||||
exec = ~/.config/polybar/trash
|
||||
format-prefix = " "
|
||||
click-right = rm -rf ~/.local/share/Trash/files/* ;exec paplay ~/.sounds/freedesktop/stereo/trash-empty.oga
|
||||
click-left = pcmanfm ~/.local/share/Trash/files
|
||||
```
|
||||
|
||||
## How it works
|
||||
* Click-left open trash
|
||||
* Click-right clean the trash
|
||||
|
||||
----------------------------------------
|
||||
|
||||
|
||||
# pulseaudio volume
|
||||
|
||||
## Dependencies
|
||||
* extra/pulseaudio
|
||||
* extra/libpulse
|
||||
* optional: extra/pavucontrol
|
||||
|
||||
## Setup
|
||||
* Create `~/.config/polybar/pavolume.sh` script (slightly changed work of [Chris Frye](https://customlinux.blogspot.ru/2013/02/pavolumesh-control-active-sink-volume.html))
|
||||
```bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# finds the active sink for pulse audio and increments the volume. useful when you have multiple audio outputs and have a key bound to vol-up and down
|
||||
|
||||
osd='no'
|
||||
inc='2'
|
||||
capvol='no'
|
||||
maxvol='200'
|
||||
autosync='yes'
|
||||
|
||||
# Muted status
|
||||
# yes: muted
|
||||
# no : not muted
|
||||
curStatus="no"
|
||||
active_sink=""
|
||||
limit=$((100 - inc))
|
||||
maxlimit=$((maxvol - inc))
|
||||
|
||||
reloadSink() {
|
||||
active_sink=$(pacmd list-sinks | awk '/* index:/{print $3}')
|
||||
}
|
||||
|
||||
function volUp {
|
||||
|
||||
getCurVol
|
||||
|
||||
if [ "$capvol" = 'yes' ]
|
||||
then
|
||||
if [ "$curVol" -le 100 ] && [ "$curVol" -ge "$limit" ]
|
||||
then
|
||||
pactl set-sink-volume "$active_sink" -- 100%
|
||||
elif [ "$curVol" -lt "$limit" ]
|
||||
then
|
||||
pactl set-sink-volume "$active_sink" -- "+$inc%"
|
||||
fi
|
||||
elif [ "$curVol" -le "$maxvol" ] && [ "$curVol" -ge "$maxlimit" ]
|
||||
then
|
||||
pactl set-sink-volume "$active_sink" "$maxvol%"
|
||||
elif [ "$curVol" -lt "$maxlimit" ]
|
||||
then
|
||||
pactl set-sink-volume "$active_sink" "+$inc%"
|
||||
fi
|
||||
|
||||
getCurVol
|
||||
|
||||
if [ ${osd} = 'yes' ]
|
||||
then
|
||||
qdbus org.kde.kded /modules/kosd showVolume "$curVol" 0
|
||||
fi
|
||||
|
||||
if [ ${autosync} = 'yes' ]
|
||||
then
|
||||
volSync
|
||||
fi
|
||||
}
|
||||
|
||||
function volDown {
|
||||
|
||||
pactl set-sink-volume "$active_sink" "-$inc%"
|
||||
getCurVol
|
||||
|
||||
if [ ${osd} = 'yes' ]
|
||||
then
|
||||
qdbus org.kde.kded /modules/kosd showVolume "$curVol" 0
|
||||
fi
|
||||
|
||||
if [ ${autosync} = 'yes' ]
|
||||
then
|
||||
volSync
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function getSinkInputs {
|
||||
input_array=$(pacmd list-sink-inputs | grep -B 4 "sink: $1 " | awk '/index:/{print $2}')
|
||||
}
|
||||
|
||||
function volSync {
|
||||
getSinkInputs "$active_sink"
|
||||
getCurVol
|
||||
|
||||
for each in $input_array
|
||||
do
|
||||
pactl set-sink-input-volume "$each" "$curVol%"
|
||||
done
|
||||
}
|
||||
|
||||
function getCurVol {
|
||||
curVol=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | grep 'volume:' | grep -E -v 'base volume:' | awk -F : '{print $3}' | grep -o -P '.{0,3}%'| sed s/.$// | tr -d ' ')
|
||||
}
|
||||
|
||||
function volMute {
|
||||
case "$1" in
|
||||
mute)
|
||||
pactl set-sink-mute "$active_sink" 1
|
||||
curVol=0
|
||||
status=1
|
||||
;;
|
||||
unmute)
|
||||
pactl set-sink-mute "$active_sink" 0
|
||||
getCurVol
|
||||
status=0
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ ${osd} = 'yes' ]
|
||||
then
|
||||
qdbus org.kde.kded /modules/kosd showVolume ${curVol} ${status}
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function volMuteStatus {
|
||||
curStatus=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | awk '/muted/{ print $2}')
|
||||
}
|
||||
|
||||
# Prints output for bar
|
||||
# Listens for events for fast update speed
|
||||
function listen {
|
||||
firstrun=0
|
||||
|
||||
pactl subscribe 2>/dev/null | {
|
||||
while true; do
|
||||
{
|
||||
# If this is the first time just continue
|
||||
# and print the current state
|
||||
# Otherwise wait for events
|
||||
# This is to prevent the module being empty until
|
||||
# an event occurs
|
||||
if [ $firstrun -eq 0 ]
|
||||
then
|
||||
firstrun=1
|
||||
else
|
||||
read -r event || break
|
||||
if ! echo "$event" | grep -e "on card" -e "on sink"
|
||||
then
|
||||
# Avoid double events
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
} &>/dev/null
|
||||
output
|
||||
done
|
||||
}
|
||||
}
|
||||
|
||||
function output() {
|
||||
reloadSink
|
||||
getCurVol
|
||||
volMuteStatus
|
||||
if [ "${curStatus}" = 'yes' ]
|
||||
then
|
||||
echo " $curVol%"
|
||||
else
|
||||
echo " $curVol%"
|
||||
fi
|
||||
} #}}}
|
||||
|
||||
reloadSink
|
||||
case "$1" in
|
||||
--up)
|
||||
volUp
|
||||
;;
|
||||
--down)
|
||||
volDown
|
||||
;;
|
||||
--togmute)
|
||||
volMuteStatus
|
||||
if [ "$curStatus" = 'yes' ]
|
||||
then
|
||||
volMute unmute
|
||||
else
|
||||
volMute mute
|
||||
fi
|
||||
;;
|
||||
--mute)
|
||||
volMute mute
|
||||
;;
|
||||
--unmute)
|
||||
volMute unmute
|
||||
;;
|
||||
--sync)
|
||||
volSync
|
||||
;;
|
||||
--listen)
|
||||
# Listen for changes and immediately create new output for the bar
|
||||
# This is faster than having the script on an interval
|
||||
listen
|
||||
;;
|
||||
*)
|
||||
# By default print output for bar
|
||||
output
|
||||
;;
|
||||
esac
|
||||
```
|
||||
|
||||
## Module
|
||||
```ini
|
||||
[module/pavolume]
|
||||
type = custom/script
|
||||
interval = 2
|
||||
label = %output%
|
||||
exec = ~/.config/polybar/pavolume.sh
|
||||
exec-if = pacmd list-sinks | grep -q available
|
||||
click-right = exec pavucontrol
|
||||
click-left = ~/.config/polybar/pavolume.sh --togmute
|
||||
scroll-up = ~/.config/polybar/pavolume.sh --up
|
||||
scroll-down = ~/.config/polybar/pavolume.sh --down
|
||||
```
|
||||
|
||||
Alternatively, if you want to use the `--listen` argument, you have to tail the output:
|
||||
```ini
|
||||
[module/pavolume]
|
||||
type = custom/script
|
||||
tail = true
|
||||
label = %output%
|
||||
exec = ~/.config/polybar/pavolume.sh --listen
|
||||
click-right = exec pavucontrol
|
||||
click-left = ~/.config/polybar/pavolume.sh --togmute
|
||||
scroll-up = ~/.config/polybar/pavolume.sh --up
|
||||
scroll-down = ~/.config/polybar/pavolume.sh --down
|
||||
```
|
||||
|
||||
----------------------------------------
|
||||
|
||||
# moc - info & control
|
||||
![mocp](https://i.imgur.com/cIcVcxy.png)
|
||||
|
||||
## Setup
|
||||
* Create `~/.config/polybar/mocp` script
|
||||
```python
|
||||
#!/usr/bin/python
|
||||
|
||||
import subprocess
|
||||
|
||||
song = stdoutdata = subprocess.getoutput("mocp -Q %song")
|
||||
album = stdoutdata = subprocess.getoutput("mocp -Q %album")
|
||||
artist = stdoutdata = subprocess.getoutput("mocp -Q %artist")
|
||||
print(song + " by " + artist + " on " + album)
|
||||
|
||||
```
|
||||
|
||||
## Module
|
||||
```ini
|
||||
[module/mocp]
|
||||
type = custom/script
|
||||
interval = 1
|
||||
format = <label>
|
||||
format-prefix = " "
|
||||
exec = ~/.config/polybar/mocp
|
||||
click-left = mocp -f
|
||||
click-right = mocp -r
|
||||
click-middle = mocp -P
|
||||
```
|
||||
|
||||
## How it works
|
||||
* Click-left Next song in playlist
|
||||
* Click-right Previous song in playlist
|
||||
* Middle-Click Pause MoC
|
||||
|
||||
----------------------------------------
|
||||
|
||||
|
||||
# cmus
|
||||
![cmus module](http://i.imgur.com/DhnQFrC.png)
|
||||
|
||||
## Dependencies
|
||||
* [cmus](http://cmus.github.io/)
|
||||
|
||||
## Setup
|
||||
Create `~/.config/polybar/cmus.sh` script. The script prepends a 0, to keep the total output length constant.
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
cmusstatus=$(cmus-remote -C status)
|
||||
grep position <<< "$cmusstatus" 1>/dev/null 2>&1
|
||||
if [ ! $? -eq 0 ]; then exit; fi
|
||||
|
||||
strindex() {- [Uptime](#uptime)
|
||||
|
||||
x="${1%%$2*}"
|
||||
[[ "$x" = "$1" ]] && echo -1 || echo "${#x}"
|
||||
}
|
||||
|
||||
prepend_zero () {
|
||||
seq -f "%02g" $1 $1
|
||||
}
|
||||
|
||||
get_all_but_first() {
|
||||
shift
|
||||
echo "$@"
|
||||
}
|
||||
|
||||
get_stat() {
|
||||
line=$(grep "$1" -m 1 <<< "$cmusstatus")
|
||||
a=$(strindex "$line" "$1")
|
||||
sub="${line:a}"
|
||||
echo "$(get_all_but_first $sub)"
|
||||
}
|
||||
|
||||
min_sec_from_sec() {
|
||||
echo -n "$(prepend_zero $(($1 / 60))):$(prepend_zero $(($1 % 60)))"
|
||||
}
|
||||
|
||||
echo -n "$(get_stat artist) - $(get_stat title) [$(min_sec_from_sec $(get_stat position)) / $(min_sec_from_sec $(get_stat duration))]"
|
||||
```
|
||||
|
||||
## Module
|
||||
```ini
|
||||
[module/cmus]
|
||||
type = custom/script
|
||||
|
||||
exec = sh ~/.config/polybar/cmus.sh
|
||||
exec-if = pgrep -x cmus
|
||||
interval = 1
|
||||
|
||||
click-left = cmus-remote --pause
|
||||
click-right = cmus-remote --stop
|
||||
```
|
||||
|
||||
----------------------------------------
|
||||
|
||||
# mpv
|
||||
|
||||
## Dependencies
|
||||
* [mpv](https://mpv.io/)
|
||||
|
||||
## Setup
|
||||
Create `~/.config/polybar/mpv.sh` script.
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
ARTIST=$(ps -u | less | grep -v vim | grep -v grep | grep 'mpv' | head -n1 | cut -d '-' -f 3- | cut -d ' ' -f 2- | cut -d '-' -f -1 | head -c -2)
|
||||
SONG=$(ps -u | less | grep -v vim | grep -v grep | grep 'mpv' | head -n1 | cut -d '-' -f 3- | cut -d ' ' -f 2- | cut -d '-' -f -2 | cut -d '-' -f 2- | tail -c +2)
|
||||
|
||||
FULL=$(ps -u | less | grep -v vim | grep -v grep | grep 'mpv' | head -n1 | cut -d '-' -f 3- | cut -d ' ' -f 2- | cut -d '-' -f -2 | head -c -2)
|
||||
|
||||
#echo -n "$ARTIST - $SONG"
|
||||
echo -n "$FULL"
|
||||
```
|
||||
|
||||
## Module
|
||||
```ini
|
||||
[module/mpv]
|
||||
type = custom/script
|
||||
|
||||
exec = sh ~/.config/polybar/mpv.sh
|
||||
exec-if = pgrep -x mpv
|
||||
interval = 1
|
||||
|
||||
format = <label>
|
||||
label = %output%
|
||||
```
|
||||
## Other languages
|
||||
|
||||
If you have written modules in other languages, link them here.
|
||||
|
|
Loading…
Reference in New Issue