From f4effc7665bf280c8587c6c65e4ee769d0244363 Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Tue, 27 Jun 2023 13:23:15 +0200 Subject: stuff --- shell-scripts/kakup | 25 +++++++++++++++++++------ shell-scripts/sb-battery | 37 +++++++++++++++++++++++++++++++++++++ shell-scripts/sb-clock | 29 +++++++++++++++++++++++++++++ shell-scripts/sb-internet | 26 ++++++++++++++++++++++++++ shell-scripts/sb-nettraf | 29 +++++++++++++++++++++++++++++ shell-scripts/sb-news | 17 +++++++++++++++++ shell-scripts/sysact | 26 ++++++++++++++++++++++++++ 7 files changed, 183 insertions(+), 6 deletions(-) create mode 100644 shell-scripts/sb-battery create mode 100644 shell-scripts/sb-clock create mode 100644 shell-scripts/sb-internet create mode 100644 shell-scripts/sb-nettraf create mode 100644 shell-scripts/sb-news create mode 100755 shell-scripts/sysact (limited to 'shell-scripts') diff --git a/shell-scripts/kakup b/shell-scripts/kakup index be12494..f2f894b 100755 --- a/shell-scripts/kakup +++ b/shell-scripts/kakup @@ -1,3 +1,4 @@ +#!@bash@/bin/bash session-or-client() { { project="$(cat -)" @@ -65,14 +66,26 @@ search() { popd >/dev/null 2>&1 } -case "${@}" in - "") client="$(pwd | session-or-client)" ;; - .) client="$(search | session-or-client)" ;; - *) client="$(echo "${@}" | session-or-client)" ;; -esac +NEW_TERM=0 +while getopts "tf" opt; do + case "$opt" in + h|\?) exit 0 ;; + t) NEW_TERM=1 ;; + f) client="$(search | session-or-client)" ;; + esac +done + +shift $((OPTIND - 1)) + +[ -z "$client" ] && { + case "${@}" in + "") client="$(pwd | session-or-client)" ;; + *) client="$(echo "${@}" | session-or-client)" ;; + esac +} [[ ! -z "$client" ]] && { - if tty -s + if [ $NEW_TERM -eq 0 ] then tmux attach -t "$client" else diff --git a/shell-scripts/sb-battery b/shell-scripts/sb-battery new file mode 100644 index 0000000..aeb7413 --- /dev/null +++ b/shell-scripts/sb-battery @@ -0,0 +1,37 @@ +#!/bin/sh + +# Prints all batteries, their percentage remaining and an emoji corresponding +# to charge status (🔌 for plugged up, 🔋 for discharging on battery, etc.). + +case $BUTTON in + 3) notify-send "🔋 Battery module" "🔋: discharging +🛑: not charging +♻: stagnant charge +🔌: charging +⚡: charged +❗: battery very low! +- Scroll to change adjust xbacklight." ;; + 4) xbacklight -inc 10 ;; + 5) xbacklight -dec 10 ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +# Loop through all attached batteries and format the info +for battery in /sys/class/power_supply/BAT?*; do + # If non-first battery, print a space separator. + [ -n "${capacity+x}" ] && printf " " + # Sets up the status and capacity + case "$(cat "$battery/status" 2>&1)" in + "Full") status="⚡" ;; + "Discharging") status="🔋" ;; + "Charging") status="🔌" ;; + "Not charging") status="🛑" ;; + "Unknown") status="♻️" ;; + *) exit 1 ;; + esac + capacity="$(cat "$battery/capacity" 2>&1)" + # Will make a warn variable if discharging and low + [ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗" + # Prints the info + printf "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn +done && printf "\\n" diff --git a/shell-scripts/sb-clock b/shell-scripts/sb-clock new file mode 100644 index 0000000..d32f787 --- /dev/null +++ b/shell-scripts/sb-clock @@ -0,0 +1,29 @@ +#!/bin/sh + +clock=$(date '+%I') + +case "$clock" in + "00") icon="🕛" ;; + "01") icon="🕐" ;; + "02") icon="🕑" ;; + "03") icon="🕒" ;; + "04") icon="🕓" ;; + "05") icon="🕔" ;; + "06") icon="🕕" ;; + "07") icon="🕖" ;; + "08") icon="🕗" ;; + "09") icon="🕘" ;; + "10") icon="🕙" ;; + "11") icon="🕚" ;; + "12") icon="🕛" ;; +esac + +case $BUTTON in + 1) notify-send "This Month" "$(cal --color=always | sed "s/..7m//;s|..27m||")" && notify-send "Appointments" "$(calcurse -d3)" ;; + 2) setsid -f "$TERMINAL" -e calcurse ;; + 3) 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" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +date "+%Y %b %d (%a) $icon%I:%M%p" diff --git a/shell-scripts/sb-internet b/shell-scripts/sb-internet new file mode 100644 index 0000000..225d376 --- /dev/null +++ b/shell-scripts/sb-internet @@ -0,0 +1,26 @@ +#!/bin/sh + +# Show wifi 📶 and percent strength or 📡 if none. +# Show 🌐 if connected to ethernet or ❎ if none. +# Show 🔒 if a vpn connection is active + +case $BUTTON in + 1) "$TERMINAL" -e nmtui; pkill -RTMIN+4 dwmblocks ;; + 3) notify-send "🌐 Internet module" "\- Click to connect +❌: wifi disabled +📡: no wifi connection +📶: wifi connection with quality +❎: no ethernet +🌐: ethernet working +🔒: vpn is active +" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +if grep -xq 'up' /sys/class/net/w*/operstate 2>/dev/null ; then + wifiicon="$(awk '/^\s*w/ { print "📶", int($3 * 100 / 70) "% " }' /proc/net/wireless)" +elif grep -xq 'down' /sys/class/net/w*/operstate 2>/dev/null ; then + grep -xq '0x1003' /sys/class/net/w*/flags && wifiicon="📡 " || wifiicon="❌ " +fi + +printf "%s%s%s\n" "$wifiicon" "$(sed "s/down/❎/;s/up/🌐/" /sys/class/net/e*/operstate 2>/dev/null)" "$(sed "s/.*/🔒/" /sys/class/net/tun*/operstate 2>/dev/null)" diff --git a/shell-scripts/sb-nettraf b/shell-scripts/sb-nettraf new file mode 100644 index 0000000..06b3c49 --- /dev/null +++ b/shell-scripts/sb-nettraf @@ -0,0 +1,29 @@ +#!/bin/sh + +# Module showing network traffic. Shows how much data has been received (RX) or +# transmitted (TX) since the previous time this script ran. So if run every +# second, gives network traffic per second. + +case $BUTTON in + 1) setsid -f "$TERMINAL" -e bmon ;; + 3) notify-send "🌐 Network traffic module" "🔻: Traffic received +🔺: Traffic transmitted" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +update() { + sum=0 + for arg; do + read -r i < "$arg" + sum=$(( sum + i )) + done + cache=/tmp/${1##*/} + [ -f "$cache" ] && read -r old < "$cache" || old=0 + printf %d\\n "$sum" > "$cache" + printf %d\\n $(( sum - old )) +} + +rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes) +tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes) + +printf "🔻%4sB 🔺%4sB\\n" $(numfmt --to=iec $rx $tx) diff --git a/shell-scripts/sb-news b/shell-scripts/sb-news new file mode 100644 index 0000000..a155c0a --- /dev/null +++ b/shell-scripts/sb-news @@ -0,0 +1,17 @@ +#!/bin/sh + +# Displays number of unread news items and an loading icon if updating. +# When clicked, brings up `newsboat`. + +case $BUTTON in + 1) setsid "$TERMINAL" -e newsboat ;; + 2) setsid -f newsup >/dev/null exit ;; + 3) notify-send "📰 News module" "\- Shows unread news items +- Shows 🔃 if updating with \`newsup\` +- Left click opens newsboat +- Middle click syncs RSS feeds +Note: Only one instance of newsboat (including updates) may be running at a time." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + + cat /tmp/newsupdate 2>/dev/null || echo "$(newsboat -x print-unread | awk '{ if($1>0) print "📰" $1}')$(cat "${XDG_CONFIG_HOME:-$HOME/.config}"/newsboat/.update 2>/dev/null)" diff --git a/shell-scripts/sysact b/shell-scripts/sysact new file mode 100755 index 0000000..64c2f32 --- /dev/null +++ b/shell-scripts/sysact @@ -0,0 +1,26 @@ +#!/bin/sh + +# A dmenu wrapper script for system functions. +export WM="dwm" +case "$(readlink -f /sbin/init)" in + *systemd*) ctl='systemctl' ;; + *) ctl='loginctl' ;; +esac + +wmpid(){ # This function is needed if there are multiple instances of the window manager. + tree="$(pstree -ps $$)" + tree="${tree#*$WM(}" + echo "${tree%%)*}" +} + +case "$(printf "🔒 lock\n🚪 leave $WM\n♻️ renew $WM\n🐻 hibernate\n🔃 reboot\n🖥️shutdown\n💤 sleep\n📺 display off" | dmenu -i -p 'Action: ')" in + '🔒 lock') slock ;; + "🚪 leave $WM") kill -TERM "$(wmpid)" ;; + "♻️ renew $WM") kill -HUP "$(wmpid)" ;; + '🐻 hibernate') slock $ctl hibernate -i ;; + '💤 sleep') slock $ctl suspend -i ;; + '🔃 reboot') $ctl reboot -i ;; + '🖥️shutdown') $ctl poweroff -i ;; + '📺 display off') xset dpms force off ;; + *) exit 1 ;; +esac -- cgit v1.2.3