From a84a8215c2c54121b81b05cf4a2123ae177b01c1 Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Thu, 23 May 2019 22:55:26 -0400 Subject: [PATCH] improved bar/ refbarr, audio binds --- .config/sxhkd/sxhkdrc | 49 +++++++++++++++++++++++---- .local/bin/dwmbar | 77 +++++++++++++++++++++++++++++++++++++++++-- .local/bin/refbar | 6 ++++ 3 files changed, 124 insertions(+), 8 deletions(-) create mode 100755 .local/bin/refbar diff --git a/.config/sxhkd/sxhkdrc b/.config/sxhkd/sxhkdrc index 2f69fcf..9015b0a 100644 --- a/.config/sxhkd/sxhkdrc +++ b/.config/sxhkd/sxhkdrc @@ -20,9 +20,9 @@ super + i super + y $TERMINAL -e calcurse -D ~/.config/calcurse super + shift + a - $TERMINAL -e alsamixer + $TERMINAL -e alsamixer; refbar super + shift + c - mpv --no-osc --no-input-default-bindings --input-conf=/dev/null --geometry=640x480-0-0 --title='mpvfloat' /dev/video0 + mpv --no-osc --no-input-default-bindings --input-conf=/dev/null --title='mpvfloat' /dev/video0 super + shift + e tutorialvids super + shift + w @@ -85,22 +85,59 @@ super + {_,shift +} bracketleft mpc seek -{10,120} # Increase volume super + {equal,plus} - amixer sset Master {5,15}%+ + amixer sset Master {5,15}%+; refbar # Decrease volume super {_,shift +} + minus - amixer sset Master {5,15}%- + amixer sset Master {5,15}%-; refbar +super + shift + m + amixer sset Master toggle; refbar + +# Audiokeys +XF86AudioMute + amixer sset Master toggle; refbar +XF86Audio{Raise,Lower}Volume + amixer sset Master 5%{+,-}; refbar +XF86Audio{Next,Prev} + mpc {next,prev} +XF86Audio{Pause,Play,Stop} + mpc {pause,play,stop} +XF86Audio{Rewind,Forward} + mpc seek {-,+}10 +XF86AudioRecord + dmenurecord +XF86AudioMedia + $TERMINAL -e ncmpcpp + +XF86PowerOff + prompt "Shutdown computer?" "sudo -A shutdown -h now" +XF86Calculator + $TERMINAL -e bc +XF86Sleep + prompt 'Hibernate computer?' 'sudo -A zzz' +XF86WWW + $BROWSER +XF86DOS + $TERMINAL +XF86ScreenSaver + mpc pause; pauseallmpv; i3lock -e -f -c 1d2021; xset dpms force off +XF86TaskPane + $TERMINAL -e htop +XF86Mail + $TERMINAL -e neomutt +XF86MyComputer + $TERMINAL -e $FILE / # Function keys # Show readme super + F1 groff -mom $HOME/.local/share/larbs/readme.mom -Tpdf | zathura - -# F2 is restart in i3 right now. +# super + F2 is mapped to restart dwm. # Change display super + F3 displayselect # Hibernate super + F4 - prompt 'Hibernate computer?' 'sudo systemctl suspend' + prompt 'Hibernate computer?' 'sudo -A zzz' # Start torrent daemon/open interface super + F6 torwrap diff --git a/.local/bin/dwmbar b/.local/bin/dwmbar index e5a2ffb..ecc436b 100755 --- a/.local/bin/dwmbar +++ b/.local/bin/dwmbar @@ -1,6 +1,79 @@ #!/bin/sh +# This script sets the statusbar with the xsetroot command at the end. + +# testweather checks to see if the most recent forecast is up to date. If it +# isn't, it downloads a new weather forecast, then signals to update the +# statusbar. Gets weather report from wttr.in. +testweather() { \ + [ "$(stat -c %y "$HOME/.local/share/weatherreport" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] && + ping -q -c 1 1.1.1.1 >/dev/null && + curl -s "wttr.in/$location" > "$HOME/.local/share/weatherreport" && + notify-send "🌞 Weather" "New weather forecast for today." && + refbar + } + +# Here is the (big) function that outputs the appearance of the statusbar. It +# can really be broken down into many submodules which I've commented and +# explained. Note that I use printf "%s" to format everything without line +# breaks. I try to put | as delimiters between modules. +status() { \ + + # Get current mpd track filename or artist - title if possible. + printf "%s" "$(mpc -f "[[%artist% - ]%title%]|[%file%]" 2>/dev/null | grep -v "volume:[0-9]*%" | head -n 1)" + + # If the weather report is current, show daily precipitation chance, + # low and high. Don't even bother to understand this one unless you + # have all day. Takes the weather report format from wttr.in and makes + # it look like how I want it for the status bar. + [ "$(stat -c %y "$HOME/.local/share/weatherreport" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] && + printf "| %s" "$(sed '16q;d' "$HOME/.local/share/weatherreport" | grep -wo "[0-9]*%" | sort -n | sed -e '$!d' | sed -e "s/^/☔ /g" | tr -d '\n')" && + sed '13q;d' "$HOME/.local/share/weatherreport" | grep -o "m\\(-\\)*[0-9]\\+" | sort -n -t 'm' -k 2n | sed -e 1b -e '$!d' | tr '\n|m' ' ' | awk '{print " ❄️",$1 "°","🌞",$2 "° |"}' + + # The newsboat module is noticeably slower than all others. + # Especially if you don't use newsboat, you will want to comment it out. + # printf ":%s |" "$(newsboat -x print-unread | cut -d' ' -f1)" + + # Get the volume of ALSA's master volume output. Show an icon if or + # not muted. + printf "%s |" "$(amixer get Master | grep -o "[0-9]*%\|\[on\]\|\[off\]" | sed "s/\[on\]//;s/\[off\]//")" + + # Wifi quality percentage and  icon if ethernet is connected. + printf " %s%s " \ + "$(grep "^\s*w" /proc/net/wireless | awk '{ print "", int($3 * 100 / 70) "%" }')" \ + "$(sed "s/down//;s/up/ /" /sys/class/net/e*/operstate)" + + # Show unread mail if mutt-wizard is installed. + command -v mw >/dev/null 2>&1 && + printf "| :%s | " "$(du -a ~/.local/share/mail/*/INBOX/new/* 2>/dev/null | wc -l)" + + # Will show all batteries with approximate icon for remaining power. + for x in /sys/class/power_supply/BAT?/capacity; + do + case "$(cat $x)" in + 100|9[0-9]) printf "" ;; + 8[0-9]|7[0-9]) printf "" ;; + 6[0-9]|5[0-9]) printf "" ;; + 4[0-9]|3[0-9]) printf "" ;; + *) printf "" ;; + esac; printf " " + done + + # Date and time. + printf "| %s" "$(date '+%Y %b %d (%a) %I:%M%p')" + } + while :; do - xsetroot -name "$(sed 's/^/🔋:/' /sys/class/power_supply/BAT?/capacity 2>/dev/null | tr '\n' ' ') $(date '+%Y %b %d (%a) %I:%M%p')" - sleep 30 + # So all that big status function was just a command that quicking gets + # what we want to be the statusbar. This xsetroot command is what sets + # it. + xsetroot -name "$(status)" + + # Check to see if new weather report is needed. + testweather & + + # Sleep for a minute after changing the status bar before updating it + # again. Note that the `refbar` "refreshes" the statusbar by killing + # this command. Feel free to change the time interval if you want. + sleep 1m done diff --git a/.local/bin/refbar b/.local/bin/refbar new file mode 100755 index 0000000..671c450 --- /dev/null +++ b/.local/bin/refbar @@ -0,0 +1,6 @@ +#!/bin/sh + +# Refresh the dwmbar. +# Right now, now this is done is by killing the sleep in the bar script. + +kill "$(pstree -lp | grep -- -dwmbar\([0-9] | sed "s/.*sleep(\([0-9]\+\)).*/\1/")"