Swap i3blocks with polybar

This commit is contained in:
2017-11-16 16:28:12 +00:00
parent b60cddc4a9
commit 511e029ec2
13 changed files with 523 additions and 162 deletions

249
polybar/config Normal file
View File

@@ -0,0 +1,249 @@
[colors]
background = #222
background-alt = #444
background-deep = #111
foreground = #dfdfdf
foreground-alt = #555
primary = #ffb52a
secondary = #e60053
alert = #bd2c40
[bar/top]
monitor = ${env:MONITOR:DVI-0}
height = 25
width = 100%
fixed-center = true
background = ${colors.background}
foreground = ${colors.foreground}
module-margin = 2
font-0 = NotoSans\-Regular:pixelsize=10;2
font-1 = FontAwesome:pixelsize=10;2
modules-left = topmenu pavolume
modules-center = cmus
modules-right = vpn ping date
[bar/bottom]
monitor = ${env:MONITOR:DVI-0}
bottom = true
width = 100%
height = 25
fixed-center = true
background = ${colors.background}
foreground = ${colors.foreground}
line-size = 0
line-color = #f00
padding-left = 0
padding-right = 4
module-margin = 4
tray-position = left
tray-padding = 5
tray-transparent = true
tray-background = #0063ff
font-0 = NotoSans\-Regular:pixelsize=10;2
font-1 = FontAwesome:pixelsize=10;2
modules-left = i3
modules-center = xwindow
modules-right = cpu memory
[bar/bottom2]
monitor = ${env:MONITOR:DVI-1}
bottom = true
width = 100%
height = 25
background = ${colors.background}
foreground = ${colors.foreground}
padding-left = 0
padding-right = 4
module-margin = 4
font-0 = fixed:pixelsize=10;2
font-1 = FontAwesome:pixelsize=10;2
modules-left = i3 bitcoin
modules-right = filesystem
[module/bspwm]
type = internal/bspwm
label-focused = %index%
label-focused-background = ${colors.background-alt}
label-focused-underline= ${colors.primary}
label-focused-padding = 2
label-occupied = %index%
label-occupied-padding = 2
label-urgent = %index%!
label-urgent-background = ${colors.alert}
label-urgent-padding = 2
label-empty = %index%
label-empty-foreground = ${colors.foreground-alt}
label-empty-padding = 2
[module/i3]
type = internal/i3
format = <label-state> <label-mode>
index-sort = true
wrapping-scroll = false
; Only show workspaces on the same output as the bar
pin-workspaces = true
label-mode-padding = 2
label-mode-foreground = #000
label-mode-background = ${colors.primary}
; focused = Active workspace on focused monitor
label-focused = %index%
label-focused-background = ${module/bspwm.label-focused-background}
label-focused-underline = ${module/bspwm.label-focused-underline}
label-focused-padding = ${module/bspwm.label-focused-padding}
; unfocused = Inactive workspace on any monitor
label-unfocused = %index%
label-unfocused-padding = ${module/bspwm.label-occupied-padding}
; visible = Active workspace on unfocused monitor
label-visible = %index%
label-visible-background = ${self.label-focused-background}
label-visible-underline = ${self.label-focused-underline}
label-visible-padding = ${self.label-focused-padding}
; urgent = Workspace with urgency hint set
label-urgent = %index%
label-urgent-background = ${module/bspwm.label-urgent-background}
label-urgent-padding = ${module/bspwm.label-urgent-padding}
[module/xwindow]
type = internal/xwindow
label = %title%
label-maxlen = 30
[module/pavolume]
type = custom/script
tail = true
label = %output%
exec = ~/.dotfiles/polybar/scripts/pavolume.sh --listen
click-right = exec pavucontrol
click-left = ~/.dotfiles/polybar/scripts/pavolume.sh --togmute
scroll-up = ~/.dotfiles/polybar/scripts/pavolume.sh --up
scroll-down = ~/.dotfiles/polybar/scripts/pavolume.sh --down
[module/bitcoin]
type = custom/script
interval = 300
format = <label>
format-prefix = " "
exec = ~/.dotfiles/polybar/scripts/bitcoin.py
[module/cmus]
type = custom/script
interval = 1
exec = ~/.dotfiles/polybar/scripts/cmus.sh
exec-if = pgrep -x cmus
label = "♪ %output%"
click-left = cmus-remote --pause
click-right = cmus-remote --stop
scroll-up = cmus-remote --next
scroll-down = cmus-remote --previous
[module/vpn]
type = custom/script
interval = 60
exec = ~/.dotfiles/polybar/scripts/ipaddr.py
exec-if = pgrep -x openvpn
label = " %output%"
[module/ping]
type = custom/script
interval = 10
exec = ~/.dotfiles/polybar/scripts/ping.py
label = "PING %output%ms"
[module/date]
type = internal/date
interval = 10
format-background = ${colors.background-deep}
format-padding = 4
date = "%a %b %e"
time = "%H:%M"
label = " %date%, %time%"
[module/topmenu]
type = custom/menu
label-open = "☰"
label-close = "✖"
label-separator = " | "
format-background = ${colors.background-deep}
format-padding = 4
expand-right = true
menu-0-0 = vpn
menu-0-0-exec = menu-open-1
menu-0-1 = sys
menu-0-1-exec = menu-open-2
menu-1-0 = kill
menu-1-0-exec = sudo killall -q openvpn
menu-1-1 = uk
menu-1-1-exec = ~/.dotfiles/bin/vpn uk &
menu-1-2 = usa
menu-1-2-exec = ~/.dotfiles/bin/vpn us &
menu-1-3 = nl
menu-1-3-exec = ~/.dotfiles/bin/vpn nl &
menu-2-0 = lock
menu-2-0-exec = ~/.dotfiles/bin/i3exit lock &
menu-2-1 = reboot
menu-2-1-exec = ~/.dotfiles/bin/i3exit reboot &
menu-2-2 = shutdown
menu-2-2-exec = ~/.dotfiles/bin/i3exit shutdown &
[module/filesystem]
type = internal/fs
interval = 5
spacing = 4
fixed-values = true
label-mounted = %mountpoint%: %free%
mount-0 = /
mount-1 = /home
mount-2 = /mnt/repo
mount-3 = /tmp
[module/cpu]
type = internal/cpu
interval = 2
format = <label> <ramp-coreload>
label = "CPU "
ramp-coreload-0 = ▁
ramp-coreload-0-foreground = #55aa55
ramp-coreload-1 = ▂
ramp-coreload-1-foreground = #55aa55
ramp-coreload-2 = ▃
ramp-coreload-2-foreground = #557755
ramp-coreload-3 = ▄
ramp-coreload-3-foreground = #557755
ramp-coreload-4 = ▅
ramp-coreload-4-foreground = #f5a70a
ramp-coreload-5 = ▆
ramp-coreload-5-foreground = #f5a70a
ramp-coreload-6 = ▇
ramp-coreload-6-foreground = #ff5555
ramp-coreload-7 = █
ramp-coreload-7-foreground = #ff5555
[module/memory]
type = internal/memory
interval = 2
format = <label> <bar-used>
label = "RAM "
bar-used-indicator =
bar-used-width = 50
bar-used-fill = |
bar-used-empty = |
bar-used-empty-foreground = ${colors.background-alt}
bar-used-foreground-0 = #55aa55
bar-used-foreground-1 = #557755
bar-used-foreground-2 = #f5a70a
bar-used-foreground-3 = #ff5555

8
polybar/launch.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env sh
killall -q polybar
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
polybar -c ~/.dotfiles/polybar/config top &
polybar -c ~/.dotfiles/polybar/config bottom &
polybar -c ~/.dotfiles/polybar/config bottom2 &
echo "Bars launched..."

8
polybar/scripts/bitcoin.py Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env python3
import requests
r = requests.get('https://blockchain.info/ticker');
ticker = r.json()
print('£%.2f' % float(ticker['GBP']['sell']))

32
polybar/scripts/cmus.sh Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
cmusstatus=$(cmus-remote -C status)
grep position <<< "$cmusstatus" 1>/dev/null 2>&1
if [ ! $? -eq 0 ]; then exit; fi
strindex() {
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))]"

15
polybar/scripts/ipaddr.py Executable file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/python
from urllib.request import urlopen
from xml.etree import ElementTree as ET
url = 'http://freegeoip.net/xml/'
with urlopen(url) as res:
s = res.read()
root = ET.fromstring(s)
ip = root.find('IP').text
country = root.find('CountryName').text
print('%s (%s)' % (ip, country))

194
polybar/scripts/pavolume.sh Executable file
View File

@@ -0,0 +1,194 @@
#!/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

7
polybar/scripts/ping.py Executable file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/python
import subprocess
import re
url = 'google.co.uk'
ps = subprocess.Popen('ping -c 1 %s | tail -1 | awk \'{print $4}\' | cut -d \'/\' -f 2' % url, shell=True, stdout=subprocess.PIPE)
print(re.sub(r'[^0-9.+]', '', str(ps.stdout.read())).split('.')[0])