From a80dbca48b09ff50274e34fbf27c09c475aa09c7 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 26 Jan 2026 17:27:50 -0600 Subject: refactor(scripts): reorganize scripts by desktop environment Move X11/DWM-specific scripts to dotfiles/dwm/.local/bin/: - All dmenu* scripts (7) - All statusbar/sb-* scripts (24) - Display scripts: brightness, displayselect, monitor, colorpick - Input scripts: remaps, toggle-touchpad, samedir - Menu scripts: exitmenu, prompt, airplanemodetoggle, audioselect - Media scripts: screenshotmenu, recordnow, setbg, wallsearch, bookfind - Misc: battery_monitor, td-toggle Delete obsolete scripts: - build.emacs.aur.sh (redundant with build-emacs.sh) - bsdnet_bounce (FreeBSD only) - calibre-install (just curls installer) - debugemacs (hardcoded paths) - gruv (duplicate of alias) - reset-auth (unclear purpose) - touchpad-indicator-start (obsolete daemon) - starth (unused Hyprland starter) Universal scripts remain in dotfiles/system/.local/bin/ for both X11 and Wayland installs. Also update todo.org: cancel pywal and waybar netspeed tasks, mark desktop file pruning done. Co-Authored-By: Claude Opus 4.5 --- dotfiles/dwm/.local/bin/airplanemodetoggle | 33 +++ dotfiles/dwm/.local/bin/audioselect | 68 ++++++ dotfiles/dwm/.local/bin/battery_monitor | 52 +++++ dotfiles/dwm/.local/bin/bookfind | 5 + dotfiles/dwm/.local/bin/brightness | 36 +++ dotfiles/dwm/.local/bin/colorpick | 6 + dotfiles/dwm/.local/bin/displayselect | 83 +++++++ dotfiles/dwm/.local/bin/dmenuexitmenu | 12 + dotfiles/dwm/.local/bin/dmenuhandler | 21 ++ dotfiles/dwm/.local/bin/dmenumount | 67 ++++++ dotfiles/dwm/.local/bin/dmenumountcifs | 19 ++ dotfiles/dwm/.local/bin/dmenurecord | 123 ++++++++++ dotfiles/dwm/.local/bin/dmenuumount | 44 ++++ dotfiles/dwm/.local/bin/dmenuunicode | 18 ++ dotfiles/dwm/.local/bin/exitmenu | 15 ++ dotfiles/dwm/.local/bin/monitor | 50 ++++ dotfiles/dwm/.local/bin/prompt | 8 + dotfiles/dwm/.local/bin/recordnow | 26 +++ dotfiles/dwm/.local/bin/remaps | 11 + dotfiles/dwm/.local/bin/samedir | 10 + dotfiles/dwm/.local/bin/screenshotmenu | 13 ++ dotfiles/dwm/.local/bin/setbg | 34 +++ dotfiles/dwm/.local/bin/statusbar/sb-battery | 37 +++ dotfiles/dwm/.local/bin/statusbar/sb-clock | 29 +++ dotfiles/dwm/.local/bin/statusbar/sb-cpu | 12 + dotfiles/dwm/.local/bin/statusbar/sb-cpubars | 44 ++++ dotfiles/dwm/.local/bin/statusbar/sb-disk | 23 ++ dotfiles/dwm/.local/bin/statusbar/sb-doppler | 279 +++++++++++++++++++++++ dotfiles/dwm/.local/bin/statusbar/sb-forecast | 35 +++ dotfiles/dwm/.local/bin/statusbar/sb-help-icon | 17 ++ dotfiles/dwm/.local/bin/statusbar/sb-internet | 26 +++ dotfiles/dwm/.local/bin/statusbar/sb-iplocate | 10 + dotfiles/dwm/.local/bin/statusbar/sb-kbselect | 16 ++ dotfiles/dwm/.local/bin/statusbar/sb-mailbox | 20 ++ dotfiles/dwm/.local/bin/statusbar/sb-memory | 12 + dotfiles/dwm/.local/bin/statusbar/sb-moonphase | 37 +++ dotfiles/dwm/.local/bin/statusbar/sb-mpdup | 8 + dotfiles/dwm/.local/bin/statusbar/sb-music | 19 ++ dotfiles/dwm/.local/bin/statusbar/sb-nettraf | 29 +++ dotfiles/dwm/.local/bin/statusbar/sb-news | 17 ++ dotfiles/dwm/.local/bin/statusbar/sb-pacpackages | 29 +++ dotfiles/dwm/.local/bin/statusbar/sb-popupgrade | 9 + dotfiles/dwm/.local/bin/statusbar/sb-price | 50 ++++ dotfiles/dwm/.local/bin/statusbar/sb-tasks | 20 ++ dotfiles/dwm/.local/bin/statusbar/sb-torrent | 27 +++ dotfiles/dwm/.local/bin/statusbar/sb-volume | 30 +++ dotfiles/dwm/.local/bin/td-toggle | 12 + dotfiles/dwm/.local/bin/toggle-touchpad | 16 ++ dotfiles/dwm/.local/bin/wallsearch | 43 ++++ 49 files changed, 1660 insertions(+) create mode 100755 dotfiles/dwm/.local/bin/airplanemodetoggle create mode 100755 dotfiles/dwm/.local/bin/audioselect create mode 100755 dotfiles/dwm/.local/bin/battery_monitor create mode 100755 dotfiles/dwm/.local/bin/bookfind create mode 100755 dotfiles/dwm/.local/bin/brightness create mode 100755 dotfiles/dwm/.local/bin/colorpick create mode 100755 dotfiles/dwm/.local/bin/displayselect create mode 100755 dotfiles/dwm/.local/bin/dmenuexitmenu create mode 100755 dotfiles/dwm/.local/bin/dmenuhandler create mode 100755 dotfiles/dwm/.local/bin/dmenumount create mode 100755 dotfiles/dwm/.local/bin/dmenumountcifs create mode 100755 dotfiles/dwm/.local/bin/dmenurecord create mode 100755 dotfiles/dwm/.local/bin/dmenuumount create mode 100755 dotfiles/dwm/.local/bin/dmenuunicode create mode 100755 dotfiles/dwm/.local/bin/exitmenu create mode 100755 dotfiles/dwm/.local/bin/monitor create mode 100755 dotfiles/dwm/.local/bin/prompt create mode 100755 dotfiles/dwm/.local/bin/recordnow create mode 100755 dotfiles/dwm/.local/bin/remaps create mode 100755 dotfiles/dwm/.local/bin/samedir create mode 100755 dotfiles/dwm/.local/bin/screenshotmenu create mode 100755 dotfiles/dwm/.local/bin/setbg create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-battery create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-clock create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-cpu create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-cpubars create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-disk create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-doppler create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-forecast create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-help-icon create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-internet create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-iplocate create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-kbselect create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-mailbox create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-memory create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-moonphase create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-mpdup create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-music create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-nettraf create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-news create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-pacpackages create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-popupgrade create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-price create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-tasks create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-torrent create mode 100755 dotfiles/dwm/.local/bin/statusbar/sb-volume create mode 100755 dotfiles/dwm/.local/bin/td-toggle create mode 100755 dotfiles/dwm/.local/bin/toggle-touchpad create mode 100755 dotfiles/dwm/.local/bin/wallsearch (limited to 'dotfiles/dwm/.local') diff --git a/dotfiles/dwm/.local/bin/airplanemodetoggle b/dotfiles/dwm/.local/bin/airplanemodetoggle new file mode 100755 index 0000000..038a0d6 --- /dev/null +++ b/dotfiles/dwm/.local/bin/airplanemodetoggle @@ -0,0 +1,33 @@ +#!/bin/bash + +if [ "$(printf "On\\nOff" | dmenu -i -p "Set airplane mode:")" = "On" ] +then + notify-send "Airplane Mode" "Turning on airplane mode...." + sudo systemctl stop bluetooth.service + sudo systemctl stop expressvpn.service + sudo systemctl stop sshd.service + systemctl --user stop syncthing.service + sudo systemctl stop avahi-daemon.service + sudo systemctl stop cronie.service + sudo systemctl stop cups.service + sudo ip link set wlp170s0 down + sudo systemctl stop wpa_supplicant.service + sudo systemctl stop NetworkManager.service + sudo nmcli radio all off + sudo powertop --auto-tune + notify-send "Airplane Mode" "Airplane mode is now on." +else + notify-send "Airplane Mode" "Turning off airplane mode....." + sudo nmcli radio wifi on + sudo systemctl start NetworkManager.service + sudo systemctl start wpa_supplicant.service + sudo ip link set wlp170s0 up + sudo systemctl start bluetooth.service + sudo systemctl start expressvpn.service + sudo systemctl start sshd.service + systemctl --user start syncthing.service + sudo systemctl start avahi-daemon.service + sudo systemctl start cronie.service + sudo systemctl start cups.service + notify-send "Airplane Mode" "Airplane mode is now off." +fi diff --git a/dotfiles/dwm/.local/bin/audioselect b/dotfiles/dwm/.local/bin/audioselect new file mode 100755 index 0000000..6c40d47 --- /dev/null +++ b/dotfiles/dwm/.local/bin/audioselect @@ -0,0 +1,68 @@ +#!/bin/sh +# Craig Jennings +# convenience script to switch audio devices +# need bluez and bluez-utils + +# DEVICE MAC ADDRESSES +marshall_earbuds_device="00:25:D1:1B:39:CA" +marshall_headset_device="9C:0D:AC:05:1E:C9" + +# SINKS (Audio Out) +marshall_headset_sink="bluez_output.9C_0D_AC_05_1E_C9.a2dp-sink" +marshall_earbuds_sink="bluez_output.00_25_D1_1B_39_CA.a2dp_sink" +builtin_sink="alsa_output.pci-0000_00_1f.3.analog-stereo" +jabra_510_sink="alsa_output.usb-0b0e_Jabra_SPEAK_510_USB_1C48F9C067D5020A00-00.analog-stereo" +steelseries_sink="alsa_output.usb-SteelSeries_SteelSeries_Arctis_7-00.stereo-game" +emberton_sink="bluez_sink.04_21_44_89_D0_BE.a2dp_sink" + +# SOURCES (Audio In) +jabra_510_source="alsa_input.usb-0b0e_Jabra_SPEAK_510_USB_1C48F9C067D5020A00-00.mono-fallback" +builtin_source="alsa_input.pci-0000_00_1f.3.analog-stereo" +steelseries_source="alsa_input.usb-SteelSeries_SteelSeries_Arctis_7-00.mono-chat" + +CHOICES="Cancel\nToggle Mute Speaker\nToggle Mute Mic\nMarshall Headset & Jabra Mic\nMarshall Headset & Default Mic\nMarshall Earbuds & Jabra Mic\nJabra Speaker & Mic\nBuilt-In Audio" + +CHOSEN=$(echo -e "$CHOICES" | dmenu -l 10) + +case "$CHOSEN" in +"Toggle Mute Speaker") + pactl set-sink-mute 0 toggle + ;; +"Toggle Mute Mic") + pactl set-source-mute 0 toggle + ;; +"Marshall Headset & Jabra Mic") + bluetooth power on + bluetoothctl connect $marshall_headset_device + pactl set-default-sink $marshall_headset_sink + pactl set-default-source $jabra_510_source + ;; +"Marshall Headset & Default Mic") + bluetooth power on + bluetoothctl connect $marshall_headset_device + pactl set-default-sink $marshall_headset_sink + pactl set-default-source $builtin_source + ;; +"Marshall Earbuds & Jabra Mic") + bluetooth power on + bluetoothctl connect $marshall_earbuds_device + pactl set-default-sink $marshall_earbuds_sink + pactl set-default-source $jabra_510_source + ;; +"Built-In Audio") + pactl set-default-sink $builtin_audio_sink + pactl set-default-source $builtin_audio_source + ;; +"Jabra Speaker & Mic") + pactl set-default-sink $jabra_510_sink + pactl set-default-source $jabra_510_source + ;; +"Emberton & Built-In") + pactl set-default-sink $emberton_sink + pactl set-default-source $builtin_audio_source + ;; +"Steelseries Headset") + pactl set-default-sink $steelseries_sink + pactl set-default-source $steelseries_source + ;; +esac diff --git a/dotfiles/dwm/.local/bin/battery_monitor b/dotfiles/dwm/.local/bin/battery_monitor new file mode 100755 index 0000000..dc8d5ea --- /dev/null +++ b/dotfiles/dwm/.local/bin/battery_monitor @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# battery_monitor +# Intended to be run via .xinitrc +# - Exit automatically if no battery (desktop) +# - When below 15%, warn user of low battery +# - When below 10%, suspend within 10 seconds if not charging +# +# Craig Jennings + +# check if acpi is installed +if ! command -v acpi &> /dev/null; then + echo "acpi is not installed. Cannot continue. Exiting...." + exit 1 +fi + +# exit if a battery exists +if [ ! -d "/sys/class/power_supply/BAT0" ] && [ ! -d "/sys/class/power_supply/BAT1" ]; then + echo "Acpi is installed but no battery detected. Assuming this is a desktop and exiting...." + exit 1 +fi + +while true; do + # Get the current battery percentage using acpi + battery_percentage=$(acpi -b | awk -F ', ' '{print $2}' | tr -d '%') + # battery_percentage=$(acpi -b | awk -F ', ' '{print $2}' | sed 's/%//') + + # When below 10%, suspend within 10 seconds if not charging + if [ "$battery_percentage" -lt 11 ] && ! acpi -a | grep -q "on-line" ; then + # Send a notification of sleeping in 10 seconds + notify-send -u critical "Critical Battery" "Battery is at $battery_percentage%. System entering sleep in 30 seconds." + + # sleep for 10 seconds, then abort if charging + sleep 30 + + # Check if the system is charging (AC adapter connected) + if acpi -a | grep -q "on-line"; then + notify-send "Charging" "The system is now charging. No action taken." + else + notify-send -u critical "Critical Battery" "Putting the system to sleep." + sudo systemctl suspend + fi + fi + + # When below 15%, warn user + if [ "$battery_percentage" -lt 15 ] && ! acpi -a | grep -q "on-line" ; then + # Send a notification using notify-send and dunst + notify-send -u critical "Low Battery" "Battery is at $battery_percentage%. System will automatically sleep at 10%." + fi + + # Sleep for 5 minutes before checking again + sleep 300 +done diff --git a/dotfiles/dwm/.local/bin/bookfind b/dotfiles/dwm/.local/bin/bookfind new file mode 100755 index 0000000..c5cc1bc --- /dev/null +++ b/dotfiles/dwm/.local/bin/bookfind @@ -0,0 +1,5 @@ +#!/bin/sh +# allows user to open a calibre book using dmenu + +find ~/Library/ -type f \( -iname \*.pdf -o -iname \*.epub \) | dmenu -i -l 20 -p "Choose an ebook:" + diff --git a/dotfiles/dwm/.local/bin/brightness b/dotfiles/dwm/.local/bin/brightness new file mode 100755 index 0000000..9142f33 --- /dev/null +++ b/dotfiles/dwm/.local/bin/brightness @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# Craig Jennings +# DWM convenience script for changing backlight +# depends on xbacklight + +increment=10 + +case $1 in + "max") + sudo xbacklight -set 100%; + ;; + "min") + sudo xbacklight -set 5%; + ;; + "up") + # get current setting as an int + current=$( printf "%.0f" "$(xbacklight -get)" ) + + # add the increment + newvalue=$(("$current" + "$increment")) + + # don't let the brightness go above 100 + [ "$newvalue" -ge 100 ] && newvalue=100; + + # set the value + xbacklight -set "$newvalue"; + ;; + "down") + current=$( printf "%.0f" "$(xbacklight -get)" ) + newvalue=$(("$current" - "$increment")) + [ "$newvalue" -le 5 ] && newvalue=5; + xbacklight -set "$newvalue"; + ;; +esac +newvalue=$( printf "%.0f" "$(xbacklight -get)") +notify-send "backlight" "backlight now set to $newvalue" diff --git a/dotfiles/dwm/.local/bin/colorpick b/dotfiles/dwm/.local/bin/colorpick new file mode 100755 index 0000000..b5e1aff --- /dev/null +++ b/dotfiles/dwm/.local/bin/colorpick @@ -0,0 +1,6 @@ +#!/bin/sh +# displays colorpicker app +# turns cursor into crosshairs, adds preview at bottom left +# selected color is added to the clipboard + +colorpicker --short --one-shot --preview | xsel -b diff --git a/dotfiles/dwm/.local/bin/displayselect b/dotfiles/dwm/.local/bin/displayselect new file mode 100755 index 0000000..f9e8062 --- /dev/null +++ b/dotfiles/dwm/.local/bin/displayselect @@ -0,0 +1,83 @@ +#!/bin/sh + +# A UI for detecting and selecting all displays. Probes xrandr for connected +# displays and lets user select one to use. User may also select "manual +# selection" which opens arandr. + +twoscreen() { # If multi-monitor is selected and there are two screens. + + mirror=$(printf "no\\nyes" | dmenu -i -p "Mirror displays?") + # Mirror displays using native resolution of external display and a scaled + # version for the internal display + if [ "$mirror" = "yes" ]; then + external=$(echo "$screens" | dmenu -i -p "Optimize resolution for:") + internal=$(echo "$screens" | grep -v "$external") + + res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | \ + tail -n 1 | awk '{print $1}') + res_internal=$(xrandr --query | sed -n "/^$internal/,/\+/p" | \ + tail -n 1 | awk '{print $1}') + + res_ext_x=$(echo "$res_external" | sed 's/x.*//') + res_ext_y=$(echo "$res_external" | sed 's/.*x//') + res_int_x=$(echo "$res_internal" | sed 's/x.*//') + res_int_y=$(echo "$res_internal" | sed 's/.*x//') + + scale_x=$(echo "$res_ext_x / $res_int_x" | bc -l) + scale_y=$(echo "$res_ext_y / $res_int_y" | bc -l) + + xrandr --output "$external" --auto --scale 1.0x1.0 \ + --output "$internal" --auto --same-as "$external" \ + --scale "$scale_x"x"$scale_y" + else + + primary=$(echo "$screens" | dmenu -i -p "Select primary display:") + secondary=$(echo "$screens" | grep -v "$primary") + direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?") + xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0 + fi + } + +morescreen() { # If multi-monitor is selected and there are more than two screens. + primary=$(echo "$screens" | dmenu -i -p "Select primary display:") + secondary=$(echo "$screens" | grep -v "$primary" | dmenu -i -p "Select secondary display:") + direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?") + tertiary=$(echo "$screens" | grep -v "$primary" | grep -v "$secondary" | dmenu -i -p "Select third display:") + xrandr --output "$primary" --auto --output "$secondary" --"$direction"-of "$primary" --auto --output "$tertiary" --"$(printf "left\\nright" | grep -v "$direction")"-of "$primary" --auto + } + +multimon() { # Multi-monitor handler. + case "$(echo "$screens" | wc -l)" in + 2) twoscreen ;; + *) morescreen ;; + esac ;} + +onescreen() { # If only one output available or chosen. + xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -) + } + +postrun() { # Stuff to run to clean up. + setbg # Fix background if screen size/arangement has changed. + remaps # Re-remap keys if keyboard added (for laptop bases) + { killall dunst ; setsid -f dunst ;} >/dev/null 2>&1 # Restart dunst to ensure proper location on screen + } + +# Get all possible displays +allposs=$(xrandr -q | grep "connected") + +# Get all connected screens. +screens=$(echo "$allposs" | awk '/ connected/ {print $1}') + +# If there's only one screen +[ "$(echo "$screens" | wc -l)" -lt 2 ] && + { onescreen "$screens"; postrun; notify-send "πŸ’» Only one screen detected." "Using it in its optimal settings..."; exit ;} + +# Get user choice including multi-monitor and manual selection: +chosen=$(printf "%s\\nmulti-monitor\\nmanual selection" "$screens" | dmenu -i -p "Select display arangement:") && +case "$chosen" in + "manual selection") arandr ; exit ;; + "multi-monitor") multimon ;; + *) onescreen "$chosen" ;; +esac + +postrun diff --git a/dotfiles/dwm/.local/bin/dmenuexitmenu b/dotfiles/dwm/.local/bin/dmenuexitmenu new file mode 100755 index 0000000..5570364 --- /dev/null +++ b/dotfiles/dwm/.local/bin/dmenuexitmenu @@ -0,0 +1,12 @@ +#!/bin/sh + +menuitems=("Lock ξ™² \nSuspend 󰀄 \nLogout 󰩈 \nReboot σ°ͺ \nShutdown  \nCancel 󰜺") +choice=$(echo -e $menuitems | dmenu -nb "#DAA520" -nf "#2E3440" -sb "#2E3440" -sf "#DAA520") + +case "$choice" in + "Logout 󰩈 ") loginctl terminate-user $(whoami) ;; + "Lock ξ™² ") slock ;; + "Suspend 󰀄 ") systemctl suspend;; + "Shutdown  ") systemctl poweroff;; + "Reboot σ°ͺ ") systemctl reboot ;; +esac diff --git a/dotfiles/dwm/.local/bin/dmenuhandler b/dotfiles/dwm/.local/bin/dmenuhandler new file mode 100755 index 0000000..1c48f3a --- /dev/null +++ b/dotfiles/dwm/.local/bin/dmenuhandler @@ -0,0 +1,21 @@ +#!/bin/sh + +# Feed this script a link and it will give dmenu +# some choice programs to use to open it. +feed="${1:-$(printf "%s" | dmenu -p 'Paste URL or file path')}" + +case "$(printf "Copy URL\\nsxiv\\nsetbg\\nPDF\\nbrowser\\nlynx\\nvim\\nmpv\\nmpv loop\\nmpv float\\nqueue download\\nqueue yt-dlp\\nqueue yt-dlp audio" | dmenu -i -p "Open it with?")" in + "Copy URL") echo "$feed" | xclip -selection clipboard ;; + mpv) setsid -f mpv -quiet "$feed" >/dev/null 2>&1 ;; + "mpv loop") setsid -f mpv -quiet --loop "$feed" >/dev/null 2>&1 ;; + "mpv float") setsid -f "$TERMINAL" -e mpv --geometry=+0-0 --autofit=30% --title="mpvfloat" "$feed" >/dev/null 2>&1 ;; + "queue yt-dlp") qndl "$feed" >/dev/null 2>&1 ;; + "queue yt-dlp audio") qndl "$feed" 'yt-dlp --embed-metadata -icx -f bestaudio/best' >/dev/null 2>&1 ;; + "queue download") qndl "$feed" 'curl -LO' >/dev/null 2>&1 ;; + PDF) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" && zathura "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" >/dev/null 2>&1 ;; + sxiv) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" && sxiv -a "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" >/dev/null 2>&1 ;; + vim) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" && setsid -f "$TERMINAL" -e "$EDITOR" "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" >/dev/null 2>&1 ;; + setbg) curl -L "$feed" > $XDG_CACHE_HOME/pic ; xwallpaper --zoom $XDG_CACHE_HOME/pic >/dev/null 2>&1 ;; + browser) setsid -f "$BROWSER" "$feed" >/dev/null 2>&1 ;; + lynx) lynx "$feed" >/dev/null 2>&1 ;; +esac diff --git a/dotfiles/dwm/.local/bin/dmenumount b/dotfiles/dwm/.local/bin/dmenumount new file mode 100755 index 0000000..3cb1f81 --- /dev/null +++ b/dotfiles/dwm/.local/bin/dmenumount @@ -0,0 +1,67 @@ +#!/bin/sh + +# Gives a dmenu prompt to mount unmounted drives and Android phones. If +# they're in /etc/fstab, they'll be mounted automatically. Otherwise, you'll +# be prompted to give a mountpoint from already existsing directories. If you +# input a novel directory, it will prompt you to create that directory. + +getmount() { \ + [ -z "$chosen" ] && exit 1 + # shellcheck disable=SC2086 + mp="$(find $1 2>/dev/null | dmenu -i -p "Type in mount point.")" || exit 1 + test -z "$mp" && exit 1 + if [ ! -d "$mp" ]; then + mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?") || exit 1 + [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp") + fi + } + +mountusb() { \ + chosen="$(echo "$usbdrives" | dmenu -i -p "Mount which drive?")" || exit 1 + chosen="$(echo "$chosen" | awk '{print $1}')" + sudo -A mount "$chosen" 2>/dev/null && notify-send "πŸ’» USB mounting" "$chosen mounted." && exit 0 + alreadymounted=$(lsblk -nrpo "name,type,mountpoint" | awk '$3!~/\/boot|\/home$|SWAP/&&length($3)>1{printf "-not ( -path *%s -prune ) ",$3}') + getmount "/mnt /media /mount /home -maxdepth 5 -type d $alreadymounted" + partitiontype="$(lsblk -no "fstype" "$chosen")" + case "$partitiontype" in + "vfat") sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000;; + "exfat") sudo -A mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)";; + *) sudo -A mount "$chosen" "$mp"; user="$(whoami)"; ug="$(groups | awk '{print $1}')"; sudo -A chown "$user":"$ug" "$mp";; + esac + notify-send "πŸ’» USB mounting" "$chosen mounted to $mp." + } + +mountandroid() { \ + chosen="$(echo "$anddrives" | dmenu -i -p "Which Android device?")" || exit 1 + chosen="$(echo "$chosen" | cut -d : -f 1)" + getmount "$HOME -maxdepth 3 -type d" + simple-mtpfs --device "$chosen" "$mp" + echo "OK" | dmenu -i -p "Tap Allow on your phone if it asks for permission and then press enter" || exit 1 + simple-mtpfs --device "$chosen" "$mp" + notify-send "πŸ€– Android Mounting" "Android device mounted to $mp." + } + +asktype() { \ + choice="$(printf "USB\\nAndroid" | dmenu -i -p "Mount a USB drive or Android device?")" || exit 1 + case $choice in + USB) mountusb ;; + Android) mountandroid ;; + esac + } + +anddrives=$(simple-mtpfs -l 2>/dev/null) +usbdrives="$(lsblk -rpo "name,type,size,mountpoint" | grep 'part\|rom' | awk '$4==""{printf "%s (%s)\n",$1,$3}')" + +if [ -z "$usbdrives" ]; then + [ -z "$anddrives" ] && echo "No USB drive or Android device detected" && exit + echo "Android device(s) detected." + mountandroid +else + if [ -z "$anddrives" ]; then + echo "USB drive(s) detected." + mountusb + else + echo "Mountable USB drive(s) and Android device(s) detected." + asktype + fi +fi diff --git a/dotfiles/dwm/.local/bin/dmenumountcifs b/dotfiles/dwm/.local/bin/dmenumountcifs new file mode 100755 index 0000000..46c2b57 --- /dev/null +++ b/dotfiles/dwm/.local/bin/dmenumountcifs @@ -0,0 +1,19 @@ +#!/bin/sh +# Gives a dmenu prompt to mount unmounted local NAS shares for read/write. +# Requirements - "%wheel ALL=(ALL) NOPASSWD: ALL" +# +# Browse for mDNS/DNS-SD services using the Avahi daemon... +srvname=$(avahi-browse _smb._tcp -t | awk '{print $4}' | dmenu -i -p "Which NAS?") || exit 1 +notify-send "Searching for network shares..." "Please wait..." +# Choose share disk... +share=$(smbclient -L "$srvname" -N | grep Disk | awk '{print $1}' | dmenu -i -p "Mount which share?") || exit 1 +# Format URL... +share2mnt=//"$srvname".local/"$share" + +sharemount() { + mounted=$(mount -v | grep "$share2mnt") || ([ ! -d /mnt/"$share" ] && sudo mkdir /mnt/"$share") + [ -z "$mounted" ] && sudo mount -t cifs "$share2mnt" -o user=nobody,password="",noperm /mnt/"$share" && notify-send "Netshare $share mounted" && exit 0 + notify-send "Netshare $share already mounted"; exit 1 +} + +sharemount diff --git a/dotfiles/dwm/.local/bin/dmenurecord b/dotfiles/dwm/.local/bin/dmenurecord new file mode 100755 index 0000000..b83a7c5 --- /dev/null +++ b/dotfiles/dwm/.local/bin/dmenurecord @@ -0,0 +1,123 @@ +#!/bin/sh + +# Usage: +# `$0`: Ask for recording type via dmenu +# `$0 screencast`: Record both audio and screen +# `$0 video`: Record only screen +# `$0 audio`: Record only audio +# `$0 kill`: Kill existing recording +# +# If there is already a running instance, user will be prompted to end it. + +updateicon() { \ + echo "$1" > /tmp/recordingicon + pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}" + } + +killrecording() { + recpid="$(cat /tmp/recordingpid)" + # kill with SIGTERM, allowing finishing touches. + kill -15 "$recpid" + rm -f /tmp/recordingpid + updateicon "" + pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}" + # even after SIGTERM, ffmpeg may still run, so SIGKILL it. + sleep 3 + kill -9 "$recpid" + exit + } + +screencast() { \ + ffmpeg -y \ + -f x11grab \ + -framerate 60 \ + -s "$(xdpyinfo | awk '/dimensions/ {print $2;}')" \ + -i "$DISPLAY" \ + -f alsa -i default \ + -r 30 \ + -c:v h264 -crf 0 -preset ultrafast -c:a aac \ + "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" & + echo $! > /tmp/recordingpid + updateicon "βΊοΈπŸŽ™οΈ" + } + +video() { ffmpeg \ + -f x11grab \ + -s "$(xdpyinfo | awk '/dimensions/ {print $2;}')" \ + -i "$DISPLAY" \ + -c:v libx264 -qp 0 -r 30 \ + "$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > /tmp/recordingpid + updateicon "⏺️" + } + +webcamhidef() { ffmpeg \ + -f v4l2 \ + -i /dev/video0 \ + -video_size 1920x1080 \ + "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > /tmp/recordingpid + updateicon "πŸŽ₯" + } + +webcam() { ffmpeg \ + -f v4l2 \ + -i /dev/video0 \ + -video_size 640x480 \ + "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > /tmp/recordingpid + updateicon "πŸŽ₯" + } + + +audio() { \ + ffmpeg \ + -f alsa -i default \ + -c:a flac \ + "$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" & + echo $! > /tmp/recordingpid + updateicon "πŸŽ™οΈ" + } + +askrecording() { \ + choice=$(printf "screencast\\nvideo\\nvideo selected\\naudio\\nwebcam\\nwebcam (hi-def)" | dmenu -i -p "Select recording style:") + case "$choice" in + screencast) screencast;; + audio) audio;; + video) video;; + *selected) videoselected;; + webcam) webcam;; + "webcam (hi-def)") webcamhidef;; + esac + } + +asktoend() { \ + response=$(printf "No\\nYes" | dmenu -i -p "Recording still active. End recording?") && + [ "$response" = "Yes" ] && killrecording + } + +videoselected() +{ + slop -f "%x %y %w %h" > /tmp/slop + read -r X Y W H < /tmp/slop + rm /tmp/slop + + ffmpeg \ + -f x11grab \ + -framerate 60 \ + -video_size "$W"x"$H" \ + -i :0.0+"$X,$Y" \ + -c:v libx264 -qp 0 -r 30 \ + "$HOME/box-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > /tmp/recordingpid + updateicon "⏺️" +} + +case "$1" in + screencast) screencast;; + audio) audio;; + video) video;; + *selected) videoselected;; + kill) killrecording;; + *) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording;; +esac diff --git a/dotfiles/dwm/.local/bin/dmenuumount b/dotfiles/dwm/.local/bin/dmenuumount new file mode 100755 index 0000000..946d12c --- /dev/null +++ b/dotfiles/dwm/.local/bin/dmenuumount @@ -0,0 +1,44 @@ +#!/bin/sh + +# A dmenu prompt to unmount drives. +# Provides you with mounted partitions, select one to unmount. +# Drives mounted at /, /boot and /home will not be options to unmount. + +unmountusb() { + [ -z "$drives" ] && exit + chosen="$(echo "$drives" | dmenu -i -p "Unmount which drive?")" || exit 1 + chosen="$(echo "$chosen" | awk '{print $1}')" + [ -z "$chosen" ] && exit + sudo -A umount "$chosen" && notify-send "πŸ’» USB unmounting" "$chosen unmounted." + } + +unmountandroid() { \ + chosen="$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -i -p "Unmount which device?")" || exit 1 + [ -z "$chosen" ] && exit + sudo -A umount -l "$chosen" && notify-send "πŸ€– Android unmounting" "$chosen unmounted." + } + +asktype() { \ + choice="$(printf "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?")" || exit 1 + case "$choice" in + USB) unmountusb ;; + Android) unmountandroid ;; + esac + } + +drives=$(lsblk -nrpo "name,type,size,mountpoint,label" | awk -F':' '{gsub(/ /,":")}$4!~/\/boot|\/efi|\/home$|SWAP/&&length($4)>1{printf "%s (%s) %s\n",$4,$3,$5}') + +if ! grep simple-mtpfs /etc/mtab; then + [ -z "$drives" ] && echo "No drives to unmount." && exit + echo "Unmountable USB drive detected." + unmountusb +else + if [ -z "$drives" ] + then + echo "Unmountable Android device detected." + unmountandroid + else + echo "Unmountable USB drive(s) and Android device(s) detected." + asktype + fi +fi diff --git a/dotfiles/dwm/.local/bin/dmenuunicode b/dotfiles/dwm/.local/bin/dmenuunicode new file mode 100755 index 0000000..b25876f --- /dev/null +++ b/dotfiles/dwm/.local/bin/dmenuunicode @@ -0,0 +1,18 @@ +#!/bin/sh + +# The famous "get a menu of emojis to copy" script. + +# Get user selection via dmenu from emoji file. +chosen=$(cut -d ';' -f1 ~/.local/share/emoji | dmenu -i -l 30 | sed "s/ .*//") + +# Exit if none chosen. +[ -z "$chosen" ] && exit + +# If you run this command with an argument, it will automatically insert the +# character. Otherwise, show a message that the emoji has been copied. +if [ -n "$1" ]; then + xdotool type "$chosen" +else + printf "$chosen" | xclip -selection clipboard + notify-send "'$chosen' copied to clipboard." & +fi diff --git a/dotfiles/dwm/.local/bin/exitmenu b/dotfiles/dwm/.local/bin/exitmenu new file mode 100755 index 0000000..54028a7 --- /dev/null +++ b/dotfiles/dwm/.local/bin/exitmenu @@ -0,0 +1,15 @@ +#!/bin/sh + +CHOICES="Shutdown\nReboot\nLock\nHibernate\nSuspend\nToggle Airplane Mode\nToggle Powersave Mode" +CHOSEN=$(echo -e "$CHOICES" | dmenu -i) + +case $CHOSEN in + "Shutdown") shutdown now ;; + "Reboot") reboot ;; + "Lock") xscreensaver-command --lock ;; + "Hiberbate") systemctl hibernate ;; + "Suspend") systemctl suspend ;; + "Toggle Airplane Mode") airplanemodetoggle ;; + "Toggle Powersave Mode") lowpowertoggle && notify-send "Battery Status" "$(acpi -b)" ;; +esac + diff --git a/dotfiles/dwm/.local/bin/monitor b/dotfiles/dwm/.local/bin/monitor new file mode 100755 index 0000000..30f04b6 --- /dev/null +++ b/dotfiles/dwm/.local/bin/monitor @@ -0,0 +1,50 @@ +#!/bin/sh +# Craig Jennings +# convenience script to switch monitors + +# this script assumes there are at most two monitors attached and we want to switch between then +CHOICES="Laptop\nLaptop-Scaled\nHome-Display\nExternal-Auto\nExternal-Scaled\nVirtualbox" + +# laptops always have a monitor connected when running the script. +LAPTOP=$(xrandr -q | grep primary | awk '$2 == "connected" {print $1}') +echo "primary monitor is $LAPTOP" + +# an external monitor will always be a connected monitor that isn't primary +EXTERNAL=$(xrandr -q | grep -v primary | awk '$2 == "connected" {print $1}') + +# start by resetting +xrandr -s 0 + +# disable if called automatically, otherwise you'll want the menu +# if there's only one monitor connected, setup laptop monitor +# if [ -z "$EXTERNAL" ]; then +# xrandr -s 0 +# xrandr --output "$LAPTOP" --auto --dpi 144 --scale 0.6 +# exit 0 +# fi + +CHOSEN=$(echo -e "$CHOICES" | dmenu -i) + +case "$CHOSEN" in +"Laptop") + xrandr --output "$LAPTOP" --auto --output "$EXTERNAL" --off + ;; +"Laptop-Scaled") + xrandr --output "$LAPTOP" --auto --dpi 144 --scale 0.6 --output "$EXTERNAL" --off + ;; +"External") + xrandr --output "$EXTERNAL" --auto --dpi 96 --mode 3440x1440 --scale 1.0 --output "$LAPTOP" --off + ;; +"External-Auto") + xrandr --output "$EXTERNAL" --auto --output "$LAPTOP" --off + ;; +"External-Scaled") + xrandr --output "$EXTERNAL" --auto --scale 0.6 --output "$LAPTOP" --off + ;; +"Virtualbox") + xrandr --output "$LAPTOP" --auto --mode 1920x1080 + ;; +esac + +# restore the wallpaper after resolution change +[ -f ~/.fehbg ] && ~/.fehbg diff --git a/dotfiles/dwm/.local/bin/prompt b/dotfiles/dwm/.local/bin/prompt new file mode 100755 index 0000000..666434f --- /dev/null +++ b/dotfiles/dwm/.local/bin/prompt @@ -0,0 +1,8 @@ +#!/bin/sh + +# A dmenu binary prompt script. +# Gives a dmenu prompt labeled with $1 to perform command $2. +# For example: +# `./prompt "Do you want to shutdown?" "shutdown -h now"` + +[ "$(printf "No\\nYes" | dmenu -i -p "$1" -nb darkred -sb red -sf white -nf gray )" = "Yes" ] && $2 diff --git a/dotfiles/dwm/.local/bin/recordnow b/dotfiles/dwm/.local/bin/recordnow new file mode 100755 index 0000000..4e2d04a --- /dev/null +++ b/dotfiles/dwm/.local/bin/recordnow @@ -0,0 +1,26 @@ +#!/usr/bin/env sh +# Craig Jennings + +# Start a screen recording using ffmpeg to capture the entire +# screen along with all audio and the microphone. + +# Make sure that ffmpeg is in the path and the destination directory +# exists. + +LOCATION="$HOME/videos/recordings" +NAME=$(date +'%Y-%m-%d-%H-%M-%S') +echo $NAME + +# create the directory if it doesn't exist +if [ ! -d "$LOCATION" ]; then + mkdir -p "$LOCATION" +fi + +# error out if ffmpeg isn't installed +if ! command -v ffmpeg &> /dev/null +then + echo "ERROR: ffmpeg couldn't be found. Please ensure it's installed and added to your PATH." + exit +fi + +ffmpeg -framerate 30 -f x11grab -i :0.0+ -f pulse -i alsa_input.pci-0000_00_1b.0.analog-stereo -ac 1 -f pulse -i alsa_output.pci-0000_00_1b.0.analog-stereo.monitor -ac 2 "$LOCATION/$NAME".mkv diff --git a/dotfiles/dwm/.local/bin/remaps b/dotfiles/dwm/.local/bin/remaps new file mode 100755 index 0000000..c95ac84 --- /dev/null +++ b/dotfiles/dwm/.local/bin/remaps @@ -0,0 +1,11 @@ +#!/bin/sh + +# This script is called on startup to remap keys. +# Decrease key repeat delay to 300ms and increase key repeat rate to 50 per second. +xset r rate 300 50 +# Map the caps lock key to super, and map the menu key to right super. +setxkbmap -option caps:super,altwin:menu_win +# When caps lock is pressed only once, treat it as escape. +killall xcape 2>/dev/null ; xcape -e 'Super_L=Escape' +# Turn off caps lock if on since there is no longer a key for it. +xset -q | grep "Caps Lock:\s*on" && xdotool key Caps_Lock diff --git a/dotfiles/dwm/.local/bin/samedir b/dotfiles/dwm/.local/bin/samedir new file mode 100755 index 0000000..371ec64 --- /dev/null +++ b/dotfiles/dwm/.local/bin/samedir @@ -0,0 +1,10 @@ +#!/bin/sh + +# Open a terminal window in the same directory as the currently active window. + +PID=$(xprop -id "$(xprop -root | xprop -root | sed -n "/_NET_ACTIVE_WINDOW/ s/^.*# // p")" | sed -n "/PID/ s/^.*= // p") +PID="$(pstree -lpA "$PID")" +PID="${PID##*"${SHELL##*/}"(}" +PID="${PID%%)*}" +cd "$(readlink /proc/"$PID"/cwd)" || return 1 +"$TERMINAL" diff --git a/dotfiles/dwm/.local/bin/screenshotmenu b/dotfiles/dwm/.local/bin/screenshotmenu new file mode 100755 index 0000000..c899dfc --- /dev/null +++ b/dotfiles/dwm/.local/bin/screenshotmenu @@ -0,0 +1,13 @@ +#!/bin/sh +# Requires maim, xdotool, and dmenu +# Uses dmenu to choose the type of screenshot to take, + +case "$(printf "full screen\\nselected area\\ncurrent window\\nselected area (copy)\\ncurrent window (copy)\\nfull screen (copy)" | dmenu -l 6 -i -p "Screenshot which area?")" in + "full screen") file="$(date +%Y.%m.%d-%M%S).png" && maim ~/pictures/screenshots/$file && notify-send "Image selection saved to ~/pictures/screenshots/$file" ;; + "full screen (5 sec delay)") file="$(date +%Y.%m.%d-%M%S).png" && sleep 5 && maim ~/pictures/screenshots/$file && notify-send "Image selection saved to ~/pictures/screenshots/$file" ;; + "selected area") file="$(date +%Y.%m.%d-%M%S).png" && maim -s ~/pictures/screenshots/$file && notify-send "Image selection saved to ~/pictures/screenshots/$file" ;; + "current window") maim -i "$(xdotool getactivewindow)" '~/pictures/screenshots/$(date +%Y.%m.%d-%M%S).png' && notify-send "Image selection saved to ~/pictures/screenshots/" ;; + "selected area (copy)") maim -s | xclip -selection clipboard -t image/png && notify-send "Image selection copied to clipboard." ;; + "current window (copy)") maim -i "$(xdotool getactivewindow)" | xclip -selection clipboard -t image/png && notify-send "Image selection copied to clipboard." ;; + "full screen (copy)") maim | xclip -selection clipboard -t image/png && notify-send "Image copied to clipboard." ;; +esac diff --git a/dotfiles/dwm/.local/bin/setbg b/dotfiles/dwm/.local/bin/setbg new file mode 100755 index 0000000..b72dc7d --- /dev/null +++ b/dotfiles/dwm/.local/bin/setbg @@ -0,0 +1,34 @@ +#!/bin/sh + +# This script does the following: +# Run by itself, set the wallpaper (at X start). +# If given a file, set that as the new wallpaper. +# If given a directory, choose random file in it. +# If wal is installed, also generates a colorscheme. + +# Location of link to wallpaper link. +bgloc="${XDG_DATA_HOME:-$HOME/.local/share}/bg" + +# Configuration files of applications that have their themes changed by pywal. +dunstconf="${XDG_CONFIG_HOME:-$HOME/.config}/dunst/dunstrc" +zathuraconf="${XDG_CONFIG_HOME:-$HOME/.config}/zathura/zathurarc" + +trueloc="$(readlink -f "$1")" && +case "$(file --mime-type -b "$trueloc")" in + image/* ) ln -sf "$(readlink -f "$1")" "$bgloc" && notify-send -i "$bgloc" "Changing wallpaper..." ;; + inode/directory ) ln -sf "$(find "$trueloc" -iregex '.*.\(jpg\|jpeg\|png\|gif\)' -type f | shuf -n 1)" "$bgloc" && notify-send -i "$bgloc" "Random Wallpaper chosen." ;; + *) notify-send "πŸ–ΌοΈ Error" "Not a valid image or directory." ; exit 1;; +esac + +# If pywal is installed, use it. +if command -v wal >/dev/null 2>&1 ; then + wal -n -i "$(readlink -f $bgloc)" -o "${XDG_CONFIG_HOME:-$HOME/.config}/wal/postrun" >/dev/null 2>&1 +# If pywal is removed, return config files to normal. +else + [ -f "$dunstconf.bak" ] && unlink "$dunstconf" && mv "$dunstconf.bak" "$dunstconf" + [ -f "$zathuraconf.bak" ] && unlink "$zathuraconf" && mv "$zathuraconf.bak" "$zathuraconf" +fi + +xwallpaper --zoom "$bgloc" +# If running, dwm hit the key to refresh the color scheme. +pidof dwm >/dev/null && xdotool key super+F5 diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-battery b/dotfiles/dwm/.local/bin/statusbar/sb-battery new file mode 100755 index 0000000..93cbe08 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/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 $BLOCK_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/dotfiles/dwm/.local/bin/statusbar/sb-clock b/dotfiles/dwm/.local/bin/statusbar/sb-clock new file mode 100755 index 0000000..e1ca8c7 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/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 $BLOCK_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/dotfiles/dwm/.local/bin/statusbar/sb-cpu b/dotfiles/dwm/.local/bin/statusbar/sb-cpu new file mode 100755 index 0000000..1572b52 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-cpu @@ -0,0 +1,12 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) notify-send "πŸ–₯ CPU hogs" "$(ps axch -o cmd:15,%cpu --sort=-%cpu | head)\\n(100% per core)" ;; + 2) setsid -f "$TERMINAL" -e htop ;; + 3) notify-send "πŸ–₯ CPU module " "\- Shows CPU temperature. +- Click to show intensive processes. +- Middle click to open htop." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +sensors | awk '/Core 0/ {print "🌑" $3}' diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-cpubars b/dotfiles/dwm/.local/bin/statusbar/sb-cpubars new file mode 100755 index 0000000..297424e --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-cpubars @@ -0,0 +1,44 @@ +#!/bin/sh + +# Module showing CPU load as a changing bars. +# Just like in polybar. +# Each bar represents amount of load on one core since +# last run. + +# Cache in tmpfs to improve speed and reduce SSD load +cache=/tmp/cpubarscache + +case $BLOCK_BUTTON in + 2) setsid -f "$TERMINAL" -e htop ;; + 3) notify-send "πŸͺ¨ CPU load module" "Each bar represents +one CPU core";; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +# id total idle +stats=$(awk '/cpu[0-9]+/ {printf "%d %d %d\n", substr($1,4), ($2 + $3 + $4 + $5), $5 }' /proc/stat) +[ ! -f $cache ] && echo "$stats" > "$cache" +old=$(cat "$cache") +printf "πŸͺ¨" +echo "$stats" | while read -r row; do + id=${row%% *} + rest=${row#* } + total=${rest%% *} + idle=${rest##* } + + case "$(echo "$old" | awk '{if ($1 == id) + printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' \ + id="$id" total="$total" idle="$idle")" in + + "0") printf "▁";; + "1") printf "β–‚";; + "2") printf "β–ƒ";; + "3") printf "β–„";; + "4") printf "β–…";; + "5") printf "β–†";; + "6") printf "β–‡";; + "7") printf "β–ˆ";; + "8") printf "β–ˆ";; + esac +done; printf "\\n" +echo "$stats" > "$cache" diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-disk b/dotfiles/dwm/.local/bin/statusbar/sb-disk new file mode 100755 index 0000000..e947509 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-disk @@ -0,0 +1,23 @@ +#!/bin/sh + +# Status bar module for disk space +# $1 should be drive mountpoint, otherwise assumed /. + +location=${1:-/} + +[ -d "$location" ] || exit + +case $BLOCK_BUTTON in + 1) notify-send "πŸ’½ Disk space" "$(df -h --output=target,used,size)" ;; + 3) notify-send "πŸ’½ Disk module" "\- Shows used hard drive space. +- Click to show all disk info." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +case "$location" in + "/home"* ) icon="🏠" ;; + "/mnt"* ) icon="πŸ’Ύ" ;; + *) icon="πŸ–₯";; +esac + +printf "%s: %s\n" "$icon" "$(df -h "$location" | awk ' /[0-9]/ {print $3 "/" $2}')" diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-doppler b/dotfiles/dwm/.local/bin/statusbar/sb-doppler new file mode 100755 index 0000000..b5833a7 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-doppler @@ -0,0 +1,279 @@ +#!/bin/sh + +# Show a Doppler RADAR of a user's preferred location. + +secs=600 # Download a new doppler radar if one hasn't been downloaded in $secs seconds. +radarloc="${XDG_CACHE_HOME:-$HOME/.cache}/radar" +doppler="${XDG_CACHE_HOME:-$HOME/.cache}/doppler.gif" + +pickloc() { chosen="$(echo "US: Northeast +US: Southeast +US: PacNorthWest +US: PacSouthWest +US: UpperMissVly +US: SouthMissVly +US: SouthPlains +US: NorthRockies +US: SouthRockies +US: Alaska +US: Carib +US: Hawaii +US: CentGrLakes +US: Conus-Large +US: KABR: Aberdeen, SD +US: KBIS: Bismarck, ND +US: KFTG: Denver/Boulder, CO +US: KDMX: Des Moines, IA +US: KDTX: Detroit, MI +US: KDDC: Dodge City, KS +US: KDLH: Duluth, MN +US: KCYS: Cheyenne, WY +US: KLOT: Chicago, IL +US: KGLD: Goodland, KS +US: KUEX: Hastings, NE +US: KGJX: Grand Junction, CO +US: KGRR: Grand Rapids, MI +US: KMVX: Fargo/Grand Forks, ND +US: KGRB: Green Bay, WI +US: KIND: Indianapolis, IN +US: KJKL: Jackson, KY +US: KARX: La Crosse, WI +US: KILX: Lincoln/Central Illinois, IL +US: KLVX: Louisville, KY +US: KMQT: Marquette +US: KMKX: Milwaukee, WI +US: KMPX: Minneapolis, MN +US: KAPX: Gaylord/Alpena, MI +US: KLNX: North Platte, NE +US: KIWX: N. Webster/Northern, IN +US: KOAX: Omaha, NE +US: KPAH: Paducah, KY +US: KEAX: Pleasant Hill, MO +US: KPUX: Pueblo, CO +US: KDVN: Quad Cities, IA +US: KUDX: Rapid City, SD +US: KRIW: Riverton, WY +US: KSGF: Springfield, MO +US: KLSX: St. LOUIS, MO +US: KFSD: Sioux Falls, IA +US: KTWX: Topeka, KS +US: KICT: Wichita, KS +US: KVWX: Paducah, KY +US: ICAO: Responsible Wfo +US: KLTX: WILMINGTON, NC +US: KCCX: State College/Central, PA +US: KLWX: Sterling, VA +US: KFCX: Blacksburg/Roanoke, VA +US: KRAX: Raleigh/Durham, NC +US: KGYX: Portland, ME +US: KDIX: Mt Holly/Philadelphia, PA +US: KPBZ: Pittsburgh, PA +US: KAKQ: Wakefield, VA +US: KMHX: Morehead City, NC +US: KGSP: Greer/Greenville/Sprtbg, SC +US: KILN: Wilmington/Cincinnati, OH +US: KCLE: Cleveland, OH +US: KCAE: Columbia, SC +US: KBGM: Binghamton, NY +US: KENX: Albany, NY +US: KBUF: Buffalo, NY +US: KCXX: Burlington, VT +US: KCBW: Caribou, ME +US: KBOX: Boston /Taunton, MA +US: KOKX: New York City, NY +US: KCLX: Charleston, SC +US: KRLX: Charleston, WV +US: ICAO: Responsible WFO +US: KBRO: Brownsville, TX +US: KABX: Albuquerque, NM +US: KAMA: Amarillo, TX +US: KFFC: Peachtree City/Atlanta, GA +US: KEWX: Austin/Sanantonio, TX +US: KBMX: Birmingham, AL +US: KCRP: Corpus Christi, TX +US: KFWS: Dallas / Ft. Worth, TX +US: KEPZ: El Paso, TX +US: KHGX: Houston/ Galveston, TX +US: KJAX: Jacksonville, FL +US: KBYX: Key West, FL +US: KMRX: Morristown/knoxville, TN +US: KLBB: Lubbock, TX +US: KLZK: Little Rock, AR +US: KLCH: Lake Charles, LA +US: KOHX: Nashville, TN +US: KMLB: Melbourne, FL +US: KNQA: Memphis, TN +US: KAMX: Miami, FL +US: KMAF: Midland/odessa, TX +US: KTLX: Norman, OK +US: KHTX: Huntsville, AL +US: KMOB: Mobile, AL +US: KTLH: Tallahassee, FL +US: KTBW: Tampa Bay Area, FL +US: KSJT: San Angelo, TX +US: KINX: Tulsa, OK +US: KSRX: Tulsa, OK +US: KLIX: New Orleans/slidell, LA +US: KDGX: Jackson, MS +US: KSHV: Shreveport, LA +US: ICAO: Responsible WFO +US: KLGX: Seattle / Tacoma, WA +US: KOTX: Spokane, WA +US: KEMX: Tucson, AZ +US: KYUX: Phoenix, AZ +US: KNKX: San Diego, CA +US: KMUX: Monterey/san Francisco, CA +US: KHNX: San Joaquin/hanford, CA +US: KSOX: San Diego, CA +US: KATX: Seattle / Tacoma, WA +US: KIWA: Phoenix, AZ +US: KRTX: Portland, OR +US: KSFX: Pocatello, ID +US: KRGX: Reno, NV +US: KDAX: Sacramento, CA +US: KMTX: Salt Lake City, UT +US: KPDT: Pendleton, OR +US: KMSX: Missoula, MT +US: KESX: Las Vegas, NV +US: KVTX: Los Angeles, CA +US: KMAX: Medford, OR +US: KFSX: Flagstaff, AZ +US: KGGW: Glasgow, MT +US: KLRX: Elko, NV +US: KBHX: Eureka, CA +US: KTFX: Great Falls, MT +US: KCBX: Boise, ID +US: KBLX: Billings, MT +US: KICX: Salt Lake City, UT +US: ICAO: Responsible Wfo W/ MSCF +US: PABC: Anchorage, AK +US: PAPD: Fairbanks, AK +US: PHKM: Honolulu, HI +US: PAHG: Anchorage, AK +US: PAKC: Anchorage, AK +US: PAIH: Anchorage, AK +US: PHMO: Honolulu, HI +US: PAEC: Fairbanks, AK +US: TJUA: San Juan, PR +US: PACG: Juneau, AK +US: PHKI: Honolulu, HI +US: PHWA: Honolulu, HI +US: ICAO: Responsible Wfo W/ MSCF +US: KFDR: Norman, OK +US: PGUA: Guam +US: KBBX: Sacramento, CA +US: KFDX: Albuquerque, NM +US: KGWX: Jackson, MS +US: KDOX: Wakefield, VA +US: KDYX: San Angelo, TX +US: KEYX: Las Vegas, NV +US: KEVX: Mobile, AL +US: KHPX: Paducah, KY +US: KTYX: Burlington, VT +US: KGRK: Dallas / Ft. Worth, TX +US: KPOE: Lake Charles, LA +US: KEOX: Tallahassee, FL +US: KHDX: El Paso, TX +US: KDFX: San Antonio, TX +US: KMXX: Birmingham, AL +US: KMBX: Bismarck, ND +US: KVAX: Jacksonville, FL +US: KJGX: Peachtree City/atlanta, GA +US: KVNX: Norman, OK +US: KVBX: Vandenberg Afb: Orcutt, CA +EU: Europe +EU: GB: Great Brittain +EU: SCAN: Scandinavia +EU: ALPS: The Alps +EU: NL: The Netherlands +EU: DE: Germany +EU: SP: Spain +EU: FR: France +EU: IT: Italy +EU: PL: Poland +EU: GR: Greece +EU: TU: Turkey +EU: RU: Russia +EU: BA: Bahrain +EU: BC: Botswana +EU: SE: Republic of Seychelles +EU: HU: Hungary +EU: UK: Ukraine +AF: AF: Africa +AF: WA: West Africa +AF: ZA: South Africa +AF: DZ: Algeria +AF: CE: Canary Islands +AF: NG: Nigeria +AF: TD: Chad +AF: CG: Democratic Republic of Congo +AF: EG: Egypt +AF: ET: Ethiopia +AF: CM: Cameroon +AF: IS: Israel +AF: LY: Libya +AF: MG: Madagascar +AF: MO: Morocco +AF: BW: Namibia +AF: SA: Saudi Arabia +AF: SO: Somalia +AF: SD: Sudan +AF: TZ: Tanzania +AF: TN: Tunisia +AF: ZM: Zambia +AF: KE: Kenya +AF: AO: Angola +DE: BAW: Baden-WΓΌrttemberg +DE: BAY: Bavaria +DE: BBB: Berlin +DE: BBB: Brandenburg +DE: HES: Hesse +DE: MVP: Mecklenburg-Western Pomerania +DE: NIB: Lower Saxony +DE: NIB: Bremen +DE: NRW: North Rhine-Westphalia +DE: RPS: Rhineland-Palatinate +DE: RPS: Saarland +DE: SAC: Saxony +DE: SAA: Saxony-Anhalt +DE: SHH: Schleswig-Holstein +DE: SHH: Hamburg +DE: THU: Thuringia" | dmenu -r -i -l 50 -p "Select a radar to use as default:" | tr "[:lower:]" "[:upper:]")" + +# Ensure user did not escape. +[ -z "$chosen" ] && exit 1 + +# Set continent code and radar code. +continentcode=${chosen%%:*} +radarcode=${chosen#* } radarcode=${radarcode%:*} + +# Print codes to $radarloc file. + printf "%s,%s\\n" "$continentcode" "$radarcode" > "$radarloc" ;} + +getdoppler() { + cont=$(cut -c -2 "$radarloc") + loc=$(cut -c 4- "$radarloc") + notify-send "🌦️ Doppler RADAR" "Pulling most recent Doppler RADAR for $loc." + case "$cont" in + "US") curl -sL "https://radar.weather.gov/ridge/lite/${loc}_loop.gif" > "$doppler" ;; + "EU") curl -sL "https://api.sat24.com/animated/${loc}/rainTMC/2/" > "$doppler" ;; + "AF") curl -sL "https://api.sat24.com/animated/${loc}/rain/2/" > "$doppler" ;; + "DE") loc="$(echo "$loc" | tr "[:upper:]" "[:lower:]")" + curl -sL "https://www.dwd.de/DWD/wetter/radar/radfilm_${loc}_akt.gif" > "$doppler" ;; + esac +} + +showdoppler() { setsid -f mpv --no-osc --loop=inf --no-terminal "$doppler" ;} + +case $BLOCK_BUTTON in + 1) [ ! -f "$radarloc" ] && pickloc && getdoppler + [ $(($(date '+%s') - $(stat -c %Y "$doppler"))) -gt "$secs" ] && getdoppler + showdoppler ;; + 2) pickloc && getdoppler && showdoppler ;; + 3) notify-send "πŸ—ΊοΈ Doppler RADAR module" "\- Left click for local Doppler RADAR. +- Middle click to update RADAR location. +After $secs seconds, new clicks will also automatically update the doppler RADAR." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +echo πŸ—ΊοΈ diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-forecast b/dotfiles/dwm/.local/bin/statusbar/sb-forecast new file mode 100755 index 0000000..45584c5 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-forecast @@ -0,0 +1,35 @@ +#!/bin/sh + +# Displays todays precipication chance (β˜”) and daily low (πŸ₯Ά) and high (🌞). +# Usually intended for the statusbar. + +# If we have internet, get a weather report from wttr.in and store it locally. +# You could set up a shell alias to view the full file in a pager in the +# terminal if desired. This function will only be run once a day when needed. +weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" +getforecast() { curl -sf "wttr.in/$LOCATION" > "$weatherreport" || exit 1 ;} + +# Some very particular and terse stream manipulation. We get the maximum +# precipitation chance and the daily high and low from the downloaded file and +# display them with coresponding emojis. +showweather() { printf "%s" "$(sed '16q;d' "$weatherreport" | + grep -wo "[0-9]*%" | sort -rn | sed "s/^/β˜”/g;1q" | tr -d '\n')" +sed '13q;d' "$weatherreport" | grep -o "m\\([-+]\\)*[0-9]\\+" | sed 's/+//g' | sort -n -t 'm' -k 2n | sed -e 1b -e '$!d' | tr '\n|m' ' ' | awk '{print " πŸ₯Ά" $1 "Β°","🌞" $2 "Β°"}' ;} + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e less -Srf "$weatherreport" ;; + 2) getforecast && showweather ;; + 3) notify-send "🌈 Weather module" "\- Left click for full forecast. +- Middle click to update forecast. +β˜”: Chance of rain/snow +πŸ₯Ά: Daily low +🌞: Daily high" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +# The test if our forcecast is updated to the day. If it isn't download a new +# weather report from wttr.in with the above function. +[ "$(stat -c %y "$weatherreport" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || + getforecast + +showweather diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-help-icon b/dotfiles/dwm/.local/bin/statusbar/sb-help-icon new file mode 100755 index 0000000..8fa4a52 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-help-icon @@ -0,0 +1,17 @@ +#!/bin/sh + +# The clickable help menu. Middle click to restart wm. + +# If dwm is running, use dwm's readme and restart. +pidof dwm >/dev/null && + READMEFILE=/usr/local/share/dwm/larbs.mom + restartwm() { pkill -HUP dwm ;} || + restartwm() { i3 restart ;} + +case $BLOCK_BUTTON in + 1) groff -mom "${READMEFILE:-${XDG_DATA_HOME:-$HOME/.local/share}/larbs/readme.mom}" -Tpdf | zathura - ;; + 2) restartwm ;; + 3) notify-send "❓ Help module" "\- Left click to open LARBS guide. +- Middle click to refresh window manager." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac; echo "❓" diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-internet b/dotfiles/dwm/.local/bin/statusbar/sb-internet new file mode 100755 index 0000000..94b7da2 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/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 $BLOCK_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/dotfiles/dwm/.local/bin/statusbar/sb-iplocate b/dotfiles/dwm/.local/bin/statusbar/sb-iplocate new file mode 100755 index 0000000..02adab8 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-iplocate @@ -0,0 +1,10 @@ +#!/bin/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 "geoip" || exit +addr="$(curl ifconfig.me 2>/dev/null)" || exit +grep "flag: " "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji" | grep "$(geoiplookup "$addr" | sed 's/.*, //')" | sed "s/flag: //;s/;.*//" diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-kbselect b/dotfiles/dwm/.local/bin/statusbar/sb-kbselect new file mode 100755 index 0000000..f0c923f --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-kbselect @@ -0,0 +1,16 @@ +#!/bin/sh +# works on any init system +# requirements: dmenu, xorg-setxkbmap +kb="$(setxkbmap -query | grep -oP 'layout:\s*\K\w+')" || exit 1 + +case $BLOCK_BUTTON in + 1) kb_choice="$(awk '/! layout/{flag=1; next} /! variant/{flag=0} flag {print $2, "- " $1}' /usr/share/X11/xkb/rules/base.lst | dmenu -l 15)" + kb="$(echo "$kb_choice" | awk '{print $3}')" + setxkbmap "$kb" + pkill -RTMIN+30 "${STATUSBAR:-dwmblocks}";; + 3) notify-send "⌨ Keyboard/language module" "$(printf "%s" "\- Current layout: $(setxkbmap -query | grep -oP 'layout:\s*\K\w+')") +- Left click to change keyboard.";; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +echo "$kb" diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-mailbox b/dotfiles/dwm/.local/bin/statusbar/sb-mailbox new file mode 100755 index 0000000..2132184 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-mailbox @@ -0,0 +1,20 @@ +#!/bin/sh + +# Displays number of unread mail and an loading icon if updating. +# When clicked, brings up `neomutt`. + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e neomutt ;; + 2) setsid -f mw -Y >/dev/null ;; + 3) notify-send "πŸ“¬ Mail module" "\- Shows unread mail +- Shows πŸ”ƒ if syncing mail +- Left click opens neomutt +- Middle click syncs mail" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +unread="$(find "${XDG_DATA_HOME:-$HOME/.local/share}"/mail/*/[Ii][Nn][Bb][Oo][Xx]/new/* -type f | wc -l 2>/dev/null)" + +pidof mbsync >/dev/null 2>&1 && icon="πŸ”ƒ" + +[ "$unread" = "0" ] && [ "$icon" = "" ] || echo "πŸ“¬$unread$icon" diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-memory b/dotfiles/dwm/.local/bin/statusbar/sb-memory new file mode 100755 index 0000000..01d3daf --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-memory @@ -0,0 +1,12 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) notify-send "🧠 Memory hogs" "$(ps axch -o cmd:15,%mem --sort=-%mem | head)" ;; + 2) setsid -f "$TERMINAL" -e htop ;; + 3) notify-send "🧠 Memory module" "\- Shows Memory Used/Total. +- Click to show memory hogs. +- Middle click to open htop." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +free --mebi | sed -n '2{p;q}' | awk '{printf ("🧠%2.2fGiB/%2.2fGiB\n", ( $3 / 1024), ($2 / 1024))}' diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-moonphase b/dotfiles/dwm/.local/bin/statusbar/sb-moonphase new file mode 100755 index 0000000..fab8b4d --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-moonphase @@ -0,0 +1,37 @@ +#!/bin/sh + +# Shows the current moon phase. + +moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase" + +[ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || + { curl -sf "wttr.in/?format=%m" > "$moonfile" || exit 1 ;} + +icon="$(cat "$moonfile")" + +case "$icon" in + πŸŒ‘) name="New" ;; + πŸŒ’) name="Waxing Crescent" ;; + πŸŒ“) name="First Quarter" ;; + πŸŒ”) name="Waxing Gibbous" ;; + πŸŒ•) name="Full" ;; + πŸŒ–) name="Waning Gibbous" ;; + πŸŒ—) name="Last Quarter" ;; + 🌘) name="Waning Crescent" ;; + *) exit 1 ;; +esac + +echo "${icon-?}" + +case $BLOCK_BUTTON in + 3) notify-send "🌜 Moon phase module" "Displays current moon phase. +- πŸŒ‘: New +- πŸŒ’: Waxing Crescent +- πŸŒ“: First Quarter +- πŸŒ”: Waxing Gibbous +- πŸŒ•: Full +- πŸŒ–: Waning Gibbous +- πŸŒ—: Last Quarter +- 🌘: Waning Crescent" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-mpdup b/dotfiles/dwm/.local/bin/statusbar/sb-mpdup new file mode 100755 index 0000000..af81a7d --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-mpdup @@ -0,0 +1,8 @@ +#!/bin/sh + +# This loop will update the mpd statusbar module whenever a command changes the +# music player's status. mpd must be running on X's start for this to work. + +while : ; do + mpc idle >/dev/null && kill -45 "$(pidof "${STATUSBAR:-dwmblocks}")" || break +done diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-music b/dotfiles/dwm/.local/bin/statusbar/sb-music new file mode 100755 index 0000000..7ea7032 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-music @@ -0,0 +1,19 @@ +#!/bin/sh + +filter() { mpc | sed "/^volume:/d;s/\\&/&/g;s/\\[paused\\].*/⏸/g;/\\[playing\\].*/d;/^ERROR/Q" | paste -sd ' ' -;} + +pidof -x sb-mpdup >/dev/null 2>&1 || sb-mpdup >/dev/null 2>&1 & + +case $BLOCK_BUTTON in + 1) mpc status | filter ; setsid -f "$TERMINAL" -e ncmpcpp ;; # right click, pause/unpause + 2) mpc toggle | filter ;; # right click, pause/unpause + 3) mpc status | filter ; notify-send "🎡 Music module" "\- Shows mpd song playing. +- ⏸ 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 + 6) mpc status | filter ; "$TERMINAL" -e "$EDITOR" "$0" ;; + *) mpc status | filter ;; +esac diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-nettraf b/dotfiles/dwm/.local/bin/statusbar/sb-nettraf new file mode 100755 index 0000000..178f677 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/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 $BLOCK_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/dotfiles/dwm/.local/bin/statusbar/sb-news b/dotfiles/dwm/.local/bin/statusbar/sb-news new file mode 100755 index 0000000..fe701db --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/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 $BLOCK_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/dotfiles/dwm/.local/bin/statusbar/sb-pacpackages b/dotfiles/dwm/.local/bin/statusbar/sb-pacpackages new file mode 100755 index 0000000..37ebed3 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-pacpackages @@ -0,0 +1,29 @@ +#!/bin/sh + +# 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. +# +# Add the following text as a file in /usr/share/libalpm/hooks/statusbar.hook: +# +# [Trigger] +# Operation = Upgrade +# Type = Package +# Target = * +# +# [Action] +# Description = Updating statusbar... +# When = PostTransaction +# Exec = /usr/bin/pkill -RTMIN+8 dwmblocks # Or i3blocks if using i3. + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e sb-popupgrade ;; + 2) notify-send "$(/usr/bin/pacman -Qu)" ;; + 3) notify-send "🎁 Upgrade module" "πŸ“¦: number of upgradable packages +- Left click to upgrade packages +- Middle click to show upgradable packages" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +pacman -Qu | grep -Fcv "[ignored]" | sed "s/^/πŸ“¦/;s/^πŸ“¦0$//g" diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-popupgrade b/dotfiles/dwm/.local/bin/statusbar/sb-popupgrade new file mode 100755 index 0000000..29d6230 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-popupgrade @@ -0,0 +1,9 @@ +#!/bin/sh + +printf "Beginning upgrade.\\n" + +yay -Syu +pkill -RTMIN+8 "${STATUSBAR:-dwmblocks}" + +printf "\\nUpgrade complete.\\nPress to exit window.\\n\\n" +read -r _ diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-price b/dotfiles/dwm/.local/bin/statusbar/sb-price new file mode 100755 index 0000000..42c84c1 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-price @@ -0,0 +1,50 @@ +#!/bin/sh + +# Usage: +# price +# price bat "Basic Attention Token" 🦁 +# When the name of the currency is multi-word, put it in quotes. + +[ -z "$3" ] && exit 1 + +# use $4 as currency, if not passed in use "usd" as default +currency="${4:-usd}" +interval="@14d" # History contained in chart preceded by '@' (7d = 7 days) +dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices" +pricefile="$dir/$1-$currency" +chartfile="$dir/$1-$currency-chart" + +updateprice() { temp="$(mktemp)" + curl -s "$currency.rate.sx/1$1" > "$temp" && + mv -f "$temp" "$pricefile" && + curl -s "$currency.rate.sx/$1$interval" > "$temp" && + mv -f "$temp" "$chartfile" ;} + +[ -d "$dir" ] || mkdir -p "$dir" + +[ "$(stat -c %x "$pricefile" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] && + updateprice "$1" + +case $BLOCK_BUTTON in + 1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;; + 2) notify-send -u low "$3 Updating..." "Updating $2 price..." + updateprice "$1" && notify-send "$3 Update complete." "$2 price is now +\$$(cat "$pricefile")" ;; + 3) uptime="$(date -d "$(stat -c %x "$pricefile")" '+%D at %T' | sed "s|$(date '+%D')|Today|")" + notify-send "$3 $2 module" "\- Exact price: \$$(cat "$pricefile") +- Left click for chart of changes. +- Middle click to update. +- Shows πŸ”ƒ if updating prices. +- Last updated: + $uptime" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +case "$currency" in + usd) symb="$" ;; + gbp) symb="Β£" ;; + eur) symb="€" ;; + btc) symb="β‚Ώ" ;; +esac + +printf "$3$symb%0.2f$after" "$(cat "$pricefile")" diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-tasks b/dotfiles/dwm/.local/bin/statusbar/sb-tasks new file mode 100755 index 0000000..586300e --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-tasks @@ -0,0 +1,20 @@ +#!/bin/sh + +# Originally by Andr3as07 +# Some changes by Luke +# Rebuild by Tenyun + +# This block displays the number running background tasks. Requires tsp. + +num=$(tsp -l | awk -v numr=0 -v numq=0 '{if (/running/)numr++; if (/queued/)numq++} END{print numr+numq"("numq")"}') + +# Handle mouse clicks +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e tsp -l ;; + 3) notify-send "Tasks module" "πŸ€–: number of running/queued background tasks +- Left click opens tsp" ;; # Right click + 2) $EDITOR "$0" ;; # Middle click +esac + +[ "$num" != "0(0)" ] && + echo "πŸ€–$num" diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-torrent b/dotfiles/dwm/.local/bin/statusbar/sb-torrent new file mode 100755 index 0000000..6527005 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-torrent @@ -0,0 +1,27 @@ +#!/bin/sh + +transmission-remote -l | grep % | + sed " # The letters are for sorting and will not appear. + s/.*Stopped.*/A πŸ›‘/; + s/.*Seeding.*/Z 🌱/; + s/.*100%.*/N βœ…/; + s/.*Idle.*/B πŸ•°οΈ/; + s/.*Uploading.*/L ⬆️/; + s/.*%.*/M ⬇️/" | + sort -h | uniq -c | awk '{print $3 $1}' | paste -sd ' ' - + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e tremc ;; + 2) td-toggle ;; + 3) notify-send "🌱 Torrent module" "\- Left click to open tremc. +- Middle click to toggle transmission. +- Shift click to edit script. +Module shows number of torrents: +πŸ›‘: paused +πŸ•°: idle (seeds needed) +πŸ”Ό: uploading (unfinished) +πŸ”½: downloading +βœ…: done +🌱: done and seeding" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac diff --git a/dotfiles/dwm/.local/bin/statusbar/sb-volume b/dotfiles/dwm/.local/bin/statusbar/sb-volume new file mode 100755 index 0000000..3cfdc45 --- /dev/null +++ b/dotfiles/dwm/.local/bin/statusbar/sb-volume @@ -0,0 +1,30 @@ +#!/bin/sh + +# Prints the current volume or πŸ”‡ if muted. + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e pulsemixer ;; + 2) pamixer -t ;; + 4) pamixer --allow-boost -i 1 ;; + 5) pamixer --allow-boost -d 1 ;; + 3) notify-send "πŸ“’ Volume module" "\- Shows volume πŸ”Š, πŸ”‡ if muted. +- Middle click to mute. +- Scroll to change." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +[ $(pamixer --get-mute) = true ] && echo πŸ”‡ && exit + +vol="$(pamixer --get-volume)" + +if [ "$vol" -gt "70" ]; then + icon="πŸ”Š" +elif [ "$vol" -gt "30" ]; then + icon="πŸ”‰" +elif [ "$vol" -gt "0" ]; then + icon="πŸ”ˆ" +else + echo πŸ”‡ && exit +fi + +echo "$icon$vol%" diff --git a/dotfiles/dwm/.local/bin/td-toggle b/dotfiles/dwm/.local/bin/td-toggle new file mode 100755 index 0000000..de1a0e6 --- /dev/null +++ b/dotfiles/dwm/.local/bin/td-toggle @@ -0,0 +1,12 @@ +#!/bin/sh + +# If transmission-daemon is running, will ask to kill, else will ask to start. + +if pidof transmission-daemon >/dev/null ; +then + [ "$(printf "No\\nYes" | dmenu -i -p "Turn off transmission-daemon?")" = "Yes" ] && killall transmission-daemon && notify-send "transmission-daemon disabled." +else + ifinstalled transmission-cli || exit + [ "$(printf "No\\nYes" | dmenu -i -p "Turn on transmission daemon?")" = "Yes" ] && transmission-daemon && notify-send "transmission-daemon enabled." +fi +sleep 3 && pkill -RTMIN+7 "${STATUSBAR:-dwmblocks}" diff --git a/dotfiles/dwm/.local/bin/toggle-touchpad b/dotfiles/dwm/.local/bin/toggle-touchpad new file mode 100755 index 0000000..9dde99b --- /dev/null +++ b/dotfiles/dwm/.local/bin/toggle-touchpad @@ -0,0 +1,16 @@ +#!/bin/sh +# Toggle touchpad status +# Using libinput and xinput + +# Use xinput list and do a search for touchpads. Then get the first one and get its name. +device="$(xinput list | grep -P '(?<= )[\w\s:]*(?i)(touchpad|synaptics)(?-i).*?(?=\s*id)' -o | head -n1)" + +# If it was activated disable it and if it wasn't disable it +if [[ "$(xinput list-props "$device" | grep -P ".*Device Enabled.*\K.(?=$)" -o)" == "1" ]] +then + xinput disable "$device" + notify-send "Touchpad" "Touchpad disabled" +else + xinput enable "$device" + notify-send "Touchpad" "Touchpad enabled" +fi diff --git a/dotfiles/dwm/.local/bin/wallsearch b/dotfiles/dwm/.local/bin/wallsearch new file mode 100755 index 0000000..f71d150 --- /dev/null +++ b/dotfiles/dwm/.local/bin/wallsearch @@ -0,0 +1,43 @@ +#!/bin/bash + +walldir="$HOME/Pictures/wallpaper/incoming" +tmpdir="$HOME/.wallsearch" +maxpage=5 +tagoptions="CANCEL\n#minimalism\n#digital art\n#4K\n#nature\n#abstract\n#landscape\n#cityscape\n#surf\n#technology" +sortoptions="CANCEL\ndate_added\nrelevance\nrandom\nfavorites\ntoplist" + +if [ -d $tmpdir ]; then + rm -rf $tmpdir +fi +mkdir -p $tmpdir + +if [ -z $1 ]; then + query=$(echo -e $tagoptions | dmenu -p "Search Wallhaven: " -i) +else + query=$1 +fi + +[ $query == "CANCEL" ] && notify-send "Cancelled wallpaper search." && exit 0; + +sorting=$(echo -e $sortoptions | dmenu -p "Sort Order: " -i) + +[ $sorting == "CANCEL" ] && notify-send "Cancelled wallpaper search." && exit 0; + +query="$(sed 's/#//g' <<<$query)" +query="$(sed 's/ /+/g' <<<$query)" +echo #query + +notify-send "wallsearch" "Searching wallpapers..." + +for i in $(seq 1 10); +do + curl -s https://wallhaven.cc/api/v1/search\?atleast\=1920x1080\&sorting\=$sorting\&q\=$query\&purity=111\&page\=$i > tmp.txt + page=$(cat tmp.txt | jq '.' | grep -Eoh "https:\/\/w\.wallhaven.cc\/full\/.*(jpg|png)\b") + wget -nc -P $tmpdir $page + notify-send "wallsearch" "Searching wallpapers..." +done + +rm tmp.txt +notify-send "wallsearch" "Done searching wallpaper." +sxiv -to $tmpdir/* | xargs -I % mv % $walldir +#rm -rf $tmpdir -- cgit v1.2.3