dotfiles

My dotfiles used for LARBS
Log | Files | Refs | README | LICENSE

commit 606946d890a7dcb1a1016a8c4b77eefcbe5c1b30
parent a5e66ac4f45322b3665c944ba34d83b7db43ebc5
Author: Luke Smith <luke@lukesmith.xyz>
Date:   Sat, 23 Nov 2019 16:23:24 -0500

statusbar scripts to master

Diffstat:
A.local/bin/statusbar/battery | 32++++++++++++++++++++++++++++++++
A.local/bin/statusbar/clock | 10++++++++++
A.local/bin/statusbar/cpu | 10++++++++++
A.local/bin/statusbar/disk | 18++++++++++++++++++
A.local/bin/statusbar/help | 7+++++++
A.local/bin/statusbar/internet | 17+++++++++++++++++
A.local/bin/statusbar/iplocate | 9+++++++++
A.local/bin/statusbar/mailbox | 16++++++++++++++++
A.local/bin/statusbar/memory | 9+++++++++
A.local/bin/statusbar/music | 18++++++++++++++++++
A.local/bin/statusbar/news | 17+++++++++++++++++
A.local/bin/statusbar/pacpackages | 18++++++++++++++++++
A.local/bin/statusbar/popupgrade | 9+++++++++
A.local/bin/statusbar/torrent | 28++++++++++++++++++++++++++++
A.local/bin/statusbar/volume | 25+++++++++++++++++++++++++
A.local/bin/statusbar/weather | 23+++++++++++++++++++++++
16 files changed, 266 insertions(+), 0 deletions(-)

diff --git a/.local/bin/statusbar/battery b/.local/bin/statusbar/battery @@ -0,0 +1,32 @@ +#!/usr/bin/env sh +# Give a battery name (e.g. BAT0) as an argument. + +case $BLOCK_BUTTON in + 3) pgrep -x dunst >/dev/null && notify-send "🔋 Battery module" "🔋: discharging +🛑: not charging +♻: stagnant charge +🔌: charging +⚡: charged +❗: battery very low! +- Text color reflects charge left" ;; +esac + +capacity=$(cat /sys/class/power_supply/"$1"/capacity) || exit +status=$(cat /sys/class/power_supply/"$1"/status) + +if [ "$capacity" -ge 75 ]; then + color="#00ff00" +elif [ "$capacity" -ge 50 ]; then + color="#ffffff" +elif [ "$capacity" -ge 25 ]; then + color="#ffff00" +else + color="#ff0000" + warn="❗" +fi + +[ -z $warn ] && warn=" " + +[ "$status" = "Charging" ] && color="#ffffff" + +printf "<span color='%s'>%s%s%s</span>\n" "$color" "$(echo "$status" | sed -e "s/,//;s/Discharging/🔋/;s/Not Charging/🛑/;s/Charging/🔌/;s/Unknown/♻️/;s/Full/⚡/;s/ 0*/ /g;s/ :/ /g")" "$warn" "$(echo "$capacity" | sed -e 's/$/%/')" diff --git a/.local/bin/statusbar/clock b/.local/bin/statusbar/clock @@ -0,0 +1,10 @@ +#!/usr/bin/env sh + +date '+%Y %b %d (%a) %I:%M%p' + +case $BLOCK_BUTTON in + 1) pgrep -x dunst >/dev/null && notify-send "This Month" "$(cal --color=always | sed "s/..7m/<b><span color=\"red\">/;s/..27m/<\/span><\/b>/")" && notify-send "Appointments" "$(calcurse -D ~/.config/calcurse -d3)" ;; + 2) $TERMINAL -e calcurse -D ~/.config/calcurse ;; + 3) pgrep -x dunst >/dev/null && notify-send "📅 Time/date module" "\- Left click to show upcoming appointments for the next three days via \`calcurse -d3\` and show the month via \`cal\` +- Middle click opens calcurse if installed" ;; +esac diff --git a/.local/bin/statusbar/cpu b/.local/bin/statusbar/cpu @@ -0,0 +1,10 @@ +#!/usr/bin/env sh + +case $BLOCK_BUTTON in + 1) notify-send "🖥 CPU hogs" "$(ps axch -o cmd:15,%cpu --sort=-%cpu | head)" ;; + 3) notify-send "🖥 CPU module " "\- Shows CPU temperature. +- Click to show intensive processes. +- % is of single core." ;; +esac + +sensors | awk '/Core 0/ {print $3}' diff --git a/.local/bin/statusbar/disk b/.local/bin/statusbar/disk @@ -0,0 +1,18 @@ +#!/usr/bin/env sh + +# Status bar module for disk space +# $1 should be drive mountpoint +# $2 is optional icon, otherwise mountpoint will displayed + +[ -z "$1" ] && exit + +icon="$2" +[ -z "$2" ] && icon="$1" + +case $BLOCK_BUTTON in + 1) pgrep -x dunst >/dev/null && notify-send "💽 Disk space" "$(df -h --output=target,used,size)" ;; + 3) pgrep -x dunst >/dev/null && notify-send "💽 Disk module" "\- Shows used hard drive space. +- Click to show all disk info." ;; +esac + +printf "%s: %s\n" "$icon" "$(df -h "$1" | awk ' /[0-9]/ {print $3 "/" $2}')" diff --git a/.local/bin/statusbar/help b/.local/bin/statusbar/help @@ -0,0 +1,7 @@ +#!/usr/bin/env sh +case $BLOCK_BUTTON in + 1) groff -mom ~/.local/share/larbs/readme.mom -Tpdf | zathura - ;; + 2) i3 restart ;; + 3) pgrep -x dunst >/dev/null && notify-send "❓ Help module" "\- Left click to open LARBS guide. +- Middle click to refresh i3.";; +esac; echo "❓" diff --git a/.local/bin/statusbar/internet b/.local/bin/statusbar/internet @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +case $BLOCK_BUTTON in + 1) $TERMINAL -e nmtui ;; + 3) pgrep -x dunst >/dev/null && notify-send "🌐 Internet module" "\- Click to connect +📡: no wifi connection +📶: wifi connection with quality +❎: no ethernet +🌐: ethernet working +" ;; +esac + +[ "$(cat /sys/class/net/w*/operstate)" = 'down' ] && wifiicon="📡" + +[ ! -n "${wifiicon+var}" ] && wifiicon=$(grep "^\s*w" /proc/net/wireless | awk '{ print "📶", int($3 * 100 / 70) "%" }') + +printf "%s %s\n" "$wifiicon" "$(cat /sys/class/net/e*/operstate | sed "s/down/❎/;s/up/🌐/")" diff --git a/.local/bin/statusbar/iplocate b/.local/bin/statusbar/iplocate @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# Gets your public ip address checks which country you are in and +# displays that information in the statusbar +# +# https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/ +ifinstalled "geoiplookup" || exit +addr="$(curl ifconfig.me 2>/dev/null)" || exit +grep "flag: " ~/.config/emoji | grep "$(geoiplookup $addr | sed 's/.*, //')" | sed "s/flag: //;s/;.*//" diff --git a/.local/bin/statusbar/mailbox b/.local/bin/statusbar/mailbox @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# i3blocks mail module. +# Displays number of unread mail and an loading icon if updating. +# When clicked, brings up `neomutt`. + +case $BLOCK_BUTTON in + 1) "$TERMINAL" -e neomutt ;; + 2) setsid mailsync >/dev/null & ;; + 3) pgrep -x dunst >/dev/null && notify-send "📬 Mail module" "\- Shows unread mail +- Shows 🔃 if syncing mail +- Left click opens neomutt +- Middle click syncs mail" ;; +esac + +echo "$(du -a ~/.local/share/mail/*/INBOX/new/* 2>/dev/null | sed -n '$=')$(cat /tmp/imapsyncicon_$USER 2>/dev/null)" diff --git a/.local/bin/statusbar/memory b/.local/bin/statusbar/memory @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +case $BLOCK_BUTTON in + 1) notify-send "🧠 Memory hogs" "$(ps axch -o cmd:15,%mem --sort=-%mem | head)" ;; + 3) notify-send "🧠 Memory module" "\- Shows Memory Used/Total. +- Click to show memory hogs." ;; +esac + +free -h | awk '/^Mem:/ {print $3 "/" $2}' diff --git a/.local/bin/statusbar/music b/.local/bin/statusbar/music @@ -0,0 +1,18 @@ +#!/usr/bin/env sh + +filter() { + sed "/^volume:/d" | tac | sed -e "s/\\&/&amp;/g;s/\\[paused\\].*/<span color=\"gray\" font_style=\"italic\">/g;s/\\[playing\\].*/<span>/g" | tr -d '\n' | sed -e "s/$/<\\/span>\n/g" + } + +case $BLOCK_BUTTON in + 1) mpc status | filter && setsid "$TERMINAL" -e ncmpcpp & ;; # right click, pause/unpause + 2) mpc toggle | filter ;; # right click, pause/unpause + 3) mpc status | filter && pgrep -x dunst >/dev/null && notify-send "🎵 Music module" "\- Shows mpd song playing. +- Italic when paused. +- Left click opens ncmpcpp. +- Middle click pauses. +- Scroll changes track.";; # right click, pause/unpause + 4) mpc prev | filter ;; # scroll up, previous + 5) mpc next | filter ;; # scroll down, next + *) mpc status | filter ;; +esac; exit diff --git a/.local/bin/statusbar/news b/.local/bin/statusbar/news @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +# i3blocks newsboat module. +# Displays number of unread news items and an loading icon if updating. +# When clicked, brings up `newsboat`. + +case $BLOCK_BUTTON in + 1) setsid "$TERMINAL" -e newsboat ;; + 2) setsid newsup >/dev/null & exit ;; + 3) pgrep -x dunst >/dev/null && notify-send "📰 News module" "\- Shows unread news items +- Shows 🔃 if updating with \`newsup\` +- Left click opens newsboat +- Middle click syncs RSS feeds +<b>Note:</b> Only one instance of newsboat (including updates) may be running at a time." ;; +esac + + cat /tmp/newsupdate 2>/dev/null || echo "$(newsboat -x print-unread | awk '{ print $1}' | sed s/^0$//g)$(cat ~/.config/newsboat/.update 2>/dev/null)" diff --git a/.local/bin/statusbar/pacpackages b/.local/bin/statusbar/pacpackages @@ -0,0 +1,18 @@ +#!/usr/bin/env sh + +# i3blocks module for pacman upgrades. +# Displays number of upgradeable packages. +# For this to work, have a `pacman -Sy` command run in the background as a +# cronjob every so often as root. This script will then read those packages. +# When clicked, it will run an upgrade via pacman. + +case $BLOCK_BUTTON in + 1) $TERMINAL -e popupgrade ;; + 2) notify-send "$(/usr/bin/pacman -Qu)" ;; + 3) pgrep -x dunst >/dev/null && notify-send "Upgrade module" "📦: number of upgradable packages +- Left click to upgrade packages +- Middle click to show upgradable packages" ;; +esac + + +pacman -Qu | grep -v "\[ignored\]" | wc -l | sed -e "s/^0$//g" diff --git a/.local/bin/statusbar/popupgrade b/.local/bin/statusbar/popupgrade @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +printf "Beginning upgrade.\\n" + +yay -Syu +pkill -RTMIN+8 i3blocks + +printf "\\nUpgrade complete.\\nPress <Enter> to exit window.\\n\\n" +read -r diff --git a/.local/bin/statusbar/torrent b/.local/bin/statusbar/torrent @@ -0,0 +1,28 @@ +#!/usr/bin/env sh + +transmission-remote -l | grep % | + sed " # This first sed command is to ensure a desirable order with sort + s/.*Stopped.*/A/g; + s/.*Seeding.*/Z/g; + s/.*100%.*/N/g; + s/.*Idle.*/B/g; + s/.*Uploading.*/L/g; + s/.*%.*/M/g" | + sort -h | uniq -c | sed " # Now we replace the standin letters with icons. + s/A/🛑/g; + s/B/⌛️/g; + s/L/🔼/g; + s/M/🔽/g; + s/N/✅/g; + s/Z/🌱/g" | awk '{print $2, $1}' | sed -e "s/ $//g" + +case $BLOCK_BUTTON in + 1) $TERMINAL -e transmission-remote-cli ;; + 3) pgrep -x dunst >/dev/null && notify-send "Torrent module" "🛑: paused +⏳: idle (seeds needed) +🔼: uploading (unfinished) +🔽: downloading +✅: done +🌱: done and seeding" ;; +esac + diff --git a/.local/bin/statusbar/volume b/.local/bin/statusbar/volume @@ -0,0 +1,25 @@ +#!/usr/bin/env sh + +case $BLOCK_BUTTON in + 1) setsid "$TERMINAL" -e pulsemixer & ;; + 2) pulsemixer --toggle-mute ;; + 4) pulsemixer --change-volume +5 ;; + 5) pulsemixer --change-volume -5 ;; + 3) pgrep -x dunst >/dev/null && notify-send "📢 Volume module" "\- Shows volume 🔊, 🔇 if muted. +- Middle click to mute. +- Scroll to change." +esac + +[ "$(pulsemixer --get-mute)" = "1" ] && printf "🔇\\n" && exit + +vol=$(pulsemixer --get-volume | awk '{print $1}') + +if [ "$vol" -gt "70" ]; then + icon="🔊" +elif [ "$vol" -lt "30" ]; then + icon="🔈" +else + icon="🔉" +fi + +printf "%s %s%%\\n" "$icon" "$vol" diff --git a/.local/bin/statusbar/weather b/.local/bin/statusbar/weather @@ -0,0 +1,23 @@ +#!/usr/bin/env sh +location="$1"; [ -z "$location" ] || { location="$location+" && rm -f "$HOME/.local/share/weatherreport" ;} + +getforecast() { ping -q -c 1 1.1.1.1 >/dev/null || exit 1 +curl -s "wttr.in/$location" > "$HOME/.local/share/weatherreport" || exit 1 ;} + +showweather() { 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 "°"}' ;} + +case $BLOCK_BUTTON in + 1) $TERMINAL -e less -S "$HOME/.local/share/weatherreport" ;; + 2) getforecast && showweather ;; + 3) pgrep -x dunst >/dev/null && notify-send "🌈 Weather module" "\- Left click for full forecast. +- Middle click to update forecast. +☔: Chance of rain/snow +❄: Daily low +🌞: Daily high" ;; +esac + +if [ "$(stat -c %y "$HOME/.local/share/weatherreport" >/dev/null 2>&1 | awk '{print $1}')" != "$(date '+%Y-%m-%d')" ] + then getforecast && showweather + else showweather +fi