diff --git a/.local/bin/camtoggle b/.local/bin/camtoggle new file mode 100755 index 0000000..2dce05f --- /dev/null +++ b/.local/bin/camtoggle @@ -0,0 +1,20 @@ +#!/bin/sh + +#pkill -f /dev/video || mpv --no-osc --no-input-default-bindings --input-conf=/dev/null --demuxer-lavf-format=v4l2 --geometry=-0-0 --autofit=30% --title="mpvfloat" --profile=low-latency --untimed /dev/video0 + +onecam() { + mpv --no-osc --no-input-default-bindings --input-conf=/dev/null mpv --demuxer-lavf-format=v4l2 --geometry=-0-0 --autofit=30% --title="mpvfloat" --profile=low-latency --untimed $1 + } + +#Get all possible cameras +allposs=$(v4l2-ctl --list-devices | sed ':a;N;$!ba;s/):\n/):/g') +cameras=$(echo "$allposs" | awk '/):/ {print $1}') + +# If there's only one camera +[ "$(echo "$cameras" | wc -l)" -lt 2 ] && + { input=$(v4l2-ctl --list-devices | sed -n "/^$cameras/,/video*/p" | tail -n 1 | awk '{print $1}') ; onecam "$input"; exit ;} + +chosen=$(echo "$cameras" | dmenu -i -p "Which camera ?") +input=$(v4l2-ctl --list-devices | sed -n "/^$chosen/,/video*/p" | tail -n 1 | awk '{print $1}') + +onecam "$input" diff --git a/.local/bin/displayselect b/.local/bin/displayselect new file mode 100755 index 0000000..daf0659 --- /dev/null +++ b/.local/bin/displayselect @@ -0,0 +1,80 @@ +#!/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//' | sed 's/i//') + res_int_x=$(echo "$res_internal" | sed 's/x.*//') + res_int_y=$(echo "$res_internal" | sed 's/.*x//' | sed 's/i//') + + 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-of\\nright-of\\nabove\\nbelow" | dmenu -i -p "What side of $primary should $secondary be on?") + xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction" "$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-of\\nright-of\\nabove\\nbelow" | 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:") + direction2=$(printf "left-of\\nright-of\\nabove\\nbelow" | dmenu -i -p "What side of $secondary should $tertiary be on?") + xrandr --output "$primary" --auto --output "$secondary" --"$direction" "$primary" --auto --output "$tertiary" --"$direction2" "$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 "$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/.local/bin/doas_askpass b/.local/bin/doas_askpass new file mode 160000 index 0000000..db7da67 --- /dev/null +++ b/.local/bin/doas_askpass @@ -0,0 +1 @@ +Subproject commit db7da6746ce9fb6276ea02eae73d439465d752a5 diff --git a/.local/bin/mounter b/.local/bin/mounter new file mode 100755 index 0000000..2c84869 --- /dev/null +++ b/.local/bin/mounter @@ -0,0 +1,105 @@ +#!/bin/bash + +# Mounts Android Phones and USB drives (encrypted or not). This script will +# replace the older `dmenumount` which had extra steps and couldn't handle +# encrypted drives. +# TODO: Remove already mounted Android phones from prompt. +# TODO: Try decrypt for drives in crtypttab +# TODO: Add some support for connecting iPhones (although they are annoying). + +set -e + +# Check for phones. +phones="$(simple-mtpfs -l 2>/dev/null | sed "s/^/πŸ“±/")" +# Check for drives. +lsblkoutput="$(lsblk -rpo "uuid,name,type,size,label,mountpoint,fstype")" +# Get all LUKS drives +allluks="$(echo "$lsblkoutput" | grep crypto_LUKS)" || true +# Get a list of the LUKS drive UUIDs already decrypted. +decrypted="$(find /dev/disk/by-id/dm-uuid-CRYPT-LUKS2-* | sed "s|.*LUKS2-||;s|-.*||")" || true +# Functioning for formatting drives correctly for dmenu: +filter() { sed "s/ /:/g" | awk -F':' '$7==""{printf "%s%s (%s) %s\n",$1,$3,$5,$6}' ; } + +# Get only LUKS drives that are not decrypted. +IFS=' +' +unopenedluks="$(for drive in $allluks; do + uuid="${drive%% *}" + uuid="${uuid//-}" # This is a bashism. + for open in $decrypted; do + [ "$uuid" = "$open" ] && break 1 + done && continue 1 + echo "πŸ”’ $drive" +done | filter)" + +# Get all normal, non-encrypted or decrypted partitions that are not mounted. +normalparts="$(echo "$lsblkoutput"| grep -v crypto_LUKS | grep 'part\|rom\|crypt' | sed "s/^/πŸ’Ύ /" | filter )" + +# Add all to one variable. If no mountable drives found, exit. +alldrives="$(echo "$phones +$unopenedluks +$normalparts" | sed "/^$/d;s/ *$//")" +test -n "$alldrives" + +# Feed all found drives to dmenu and get user choice. +chosen="$(echo "$alldrives" | dmenu -p "Mount which drive?" -i)" + +# Function for prompting user for a mountpoint. +getmount(){ + mp="$(find /mnt /media /mount /home -maxdepth 1 -type d 2>/dev/null | dmenu -i -p "Mount this drive where?")" + test -n "$mp" + if [ ! -d "$mp" ]; then + mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?") + [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp") + fi +} + +attemptmount(){ + # Attempt to mount without a mountpoint, to see if drive is in fstab. + sudo -A mount "$chosen" || return 1 + notify-send "πŸ’ΎDrive Mounted." "$chosen mounted." + exit +} + +case "$chosen" in + πŸ’Ύ*) + chosen="${chosen%% *}" + chosen="${chosen:1}" # This is a bashism. + attemptmount || getmount + partitiontype="$(lsblk -no "fstype" "$chosen")" + case "$partitiontype" in + "vfat") sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000;; + *) sudo -A mount "$chosen" "$mp"; user="$(whoami)"; ug="$(groups | awk '{print $1}')"; sudo -A chown "$user":"$ug" "$mp";; + esac + # sudo -A mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)" + notify-send "πŸ’ΎDrive Mounted." "$chosen mounted to $mp." + ;; + + πŸ”’*) + chosen="${chosen%% *}" + chosen="${chosen:1}" # This is a bashism. + # Number the drive. + while true; do + [ -f "/dev/mapper/usb$num" ] || break + num="$(printf "%02d" "$((num +1))")" + done + + # Decrypt in a terminal window + ${TERMINAL:-st} -n floatterm -g 60x1 -e sudo cryptsetup open "$chosen" "usb$num" + # Check if now decrypted. + test -b "/dev/mapper/usb$num" + + attemptmount || getmount + sudo -A mount "/dev/mapper/usb$num" "$mp" -o uid="$(id -u)",gid="$(id -g)" + notify-send "πŸ”“Decrypted drive Mounted." "$chosen decrypted and mounted to $mp." + ;; + + πŸ“±*) + notify-send "❗Note" "Remember to allow file access on your phone now." + getmount + chosen="${chosen%%:*}" + chosen="${chosen:1}" # This is a bashism. + sudo -A simple-mtpfs -o allow_other --device "$chosen" "$mp" + notify-send "πŸ€– Android Mounted." "Android device mounted to $mp." + ;; +esac diff --git a/.local/bin/pauseallmpv b/.local/bin/pauseallmpv new file mode 100755 index 0000000..d69a414 --- /dev/null +++ b/.local/bin/pauseallmpv @@ -0,0 +1,10 @@ +#!/bin/sh + +# You might notice all mpv commands are aliased to have this input-ipc-server +# thing. That's just for this particular command, which allows us to pause +# every single one of them with one command! This is bound to super + shift + p +# (with other things) by default and is used in some other places. + +for i in $(ls /tmp/mpvSockets/*); do + echo '{ "command": ["set_property", "pause", true] }' | socat - "$i"; +done diff --git a/.local/bin/queueandnotify b/.local/bin/queueandnotify new file mode 100755 index 0000000..a54b13e --- /dev/null +++ b/.local/bin/queueandnotify @@ -0,0 +1,14 @@ +#!/bin/sh + +# Podboat sucks. This script replaces it. +# It reads the newsboat queue, queuing downloads with taskspooler. +# It also removes the junk from extentions. +queuefile="${XDG_DATA_HOME:-$HOME/.local/share}/newsboat/queue" + +while read -r line; do + [ -z "$line" ] && continue + url="$(echo "$line" | awk '{print $1}')" + qndl "$url" "curl -LO" +done < "$queuefile" + +echo > "$queuefile" diff --git a/.local/bin/remaps b/.local/bin/remaps new file mode 100755 index 0000000..9b431b5 --- /dev/null +++ b/.local/bin/remaps @@ -0,0 +1,14 @@ +#!/bin/sh + +# This script is called on startup to remap keys. +# Increase key speed via a rate change +xset r rate 300 50 +# Map the caps lock key to super... +setxkbmap -option caps:super +# But when it is pressed only once, treat it as escape. +killall xcape 2>/dev/null ; xcape -e 'Super_L=Escape' +# Map the menu button to right super as well. +xmodmap -e 'keycode 135 = Super_R' + +# Map the multimedia button +xmodmap -e 'keycode 179 = XF86AudioMedia NoSymbol XF86AudioMedia' diff --git a/.local/bin/rssadd b/.local/bin/rssadd new file mode 100755 index 0000000..2ce421b --- /dev/null +++ b/.local/bin/rssadd @@ -0,0 +1,10 @@ +#!/bin/sh + +! echo "$1" | grep "https*://\S\+\.[A-Za-z]\+\S*" >/dev/null && + notify-send "That doesn't look like a full URL." && exit +RSSFILE="${XDG_CONFIG_HOME:-$HOME/.config}/newsboat/urls" +if awk '{print $1}' "$RSSFILE" | grep "^$1$" >/dev/null; then + notify-send "You already have this RSS feed." +else + echo "$1" >> "$RSSFILE" && notify-send "RSS feed added." +fi diff --git a/.local/bin/setbg b/.local/bin/setbg new file mode 100755 index 0000000..5f70fa5 --- /dev/null +++ b/.local/bin/setbg @@ -0,0 +1,20 @@ +#!/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" + +[ -f "$1" ] && ln -sf "$(readlink -f "$1")" "$bgloc" && notify-send -i "$bgloc" "Changing wallpaper..." + +[ -d "$1" ] && ln -sf "$(find "$(readlink -f "$1")" -iregex '.*.\(jpg\|jpeg\|png\|gif\)' -type f | shuf -n 1)" "$bgloc" && notify-send -i "$bgloc" "Random Wallpaper chosen." + +# If pywal is installed, use it. +wal -i "$(readlink -f "$bgloc")" -o "${XDG_CONFIG_HOME:-$HOME/.config}/wal/postrun" >/dev/null 2>&1 + +pidof dwm >/dev/null && xdotool key super+F12 +xwallpaper --zoom "$bgloc" diff --git a/.local/bin/shortcuts b/.local/bin/shortcuts new file mode 100755 index 0000000..73132da --- /dev/null +++ b/.local/bin/shortcuts @@ -0,0 +1,31 @@ +#!/bin/sh + +# Output locations. Unactivated progs should go to /dev/null. +shell_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc" +zsh_named_dirs="${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshnameddirrc" +ranger_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/ranger/shortcuts.conf" +qute_shortcuts="/dev/null" +fish_shortcuts="/dev/null" +vifm_shortcuts="/dev/null" + +# Remove, prepare files +rm -f "$ranger_shortcuts" "$qute_shortcuts" "$zsh_named_dirs" 2>/dev/null +printf "# vim: filetype=sh\\n" > "$fish_shortcuts" +printf "# vim: filetype=sh\\nalias " > "$shell_shortcuts" +printf "\" vim: filetype=vim\\n" > "$vifm_shortcuts" + +# Format the `directories` file in the correct syntax and sent it to all three configs. +awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\"); + printf(\"%s=\42cd %s && ls -a\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ; + printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ; + printf(\"abbr %s \42cd %s; and ls -a\42\n\",\$1,\$2) >> \"$fish_shortcuts\" ; + printf(\"map g%s :cd %s\nmap t%s :cd %s\nmap M%s :cd %s:mo\nmap Y%s :cd %s:co \n\",\$1,\$2, \$1, \$2, \$1, \$2, \$1, \$2) >> \"$vifm_shortcuts\" ; + printf(\"config.bind(';%s', \42set downloads.location.directory %s ;; hint links download\42) \n\",\$1,\$2) >> \"$qute_shortcuts\" ; + printf(\"map g%s cd %s\nmap t%s tab_new %s\nmap m%s shell mv -v %%s %s\nmap Y%s shell cp -rv %%s %s \n\",\$1,\$2,\$1,\$2, \$1, \$2, \$1, \$2) >> \"$ranger_shortcuts\" }" "${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs" + +# Format the `files` file in the correct syntax and sent it to both configs. +awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\"); + printf(\"%s=\42\$EDITOR %s\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ; + printf(\"abbr %s \42\$EDITOR %s\42 \n\",\$1,\$2) >> \"$fish_shortcuts\" ; + printf(\"map %s :e %s \n\",\$1,\$2) >> \"$vifm_shortcuts\" ; + printf(\"map %s shell \$EDITOR %s \n\",\$1,\$2) >> \"$ranger_shortcuts\" }" "${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-files" diff --git a/.local/bin/statusbar/sb-battery b/.local/bin/statusbar/sb-battery new file mode 100755 index 0000000..ef558f8 --- /dev/null +++ b/.local/bin/statusbar/sb-battery @@ -0,0 +1,39 @@ +#!/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 +- Scroll to change adjust xbacklight." ;; + 4) xbacklight -inc 10 ;; + 5) xbacklight -dec 10 ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +# acpi alternative +acpi | sed "s/Battery [0-9]: //;s/[Dd]ischarging, /πŸ”‹/;s/[Nn]ot charging, /πŸ›‘/;s/[Cc]harging, /πŸ”Œ/;s/[Uu]nknown, /♻️/;s/[Ff]ull, /⚑/;s/ \(remaining\|until charged\)//"; exit +done | sed 's/ *$//' + +# 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")" in +# "Full") status="⚑" ;; +# "Discharging") status="πŸ”‹" ;; +# "Charging") status="πŸ”Œ" ;; +# "Not charging") status="πŸ›‘" ;; +# "Unknown") status="♻️" ;; +# esac +# capacity=$(cat "$battery/capacity") +# # 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 && exit 0 diff --git a/.local/bin/statusbar/sb-clock b/.local/bin/statusbar/sb-clock new file mode 100755 index 0000000..c8ace8f --- /dev/null +++ b/.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 -m --color=always | sed "s/..7m//;s/..27m/<\/span><\/b>/")" && 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 "+%d %b %Y (%a) $icon%H:%M" diff --git a/.local/bin/statusbar/sb-cpu b/.local/bin/statusbar/sb-cpu new file mode 100755 index 0000000..1572b52 --- /dev/null +++ b/.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/.local/bin/statusbar/sb-cpubars b/.local/bin/statusbar/sb-cpubars new file mode 100755 index 0000000..297424e --- /dev/null +++ b/.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/.local/bin/statusbar/sb-disk b/.local/bin/statusbar/sb-disk new file mode 100755 index 0000000..e947509 --- /dev/null +++ b/.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/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast new file mode 100755 index 0000000..7b8416e --- /dev/null +++ b/.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_DATA_HOME:-$HOME/.local/share}/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/.local/bin/statusbar/sb-internet b/.local/bin/statusbar/sb-internet new file mode 100755 index 0000000..ee1a160 --- /dev/null +++ b/.local/bin/statusbar/sb-internet @@ -0,0 +1,24 @@ +#!/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 +πŸ“‘: no wifi connection +πŸ“Ά: wifi connection with quality +❎: no ethernet +🌐: ethernet working +πŸ”’: vpn is active +" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +case "$(cat /sys/class/net/w*/operstate 2>/dev/null)" in + down) wifiicon="πŸ“‘ " ;; + up) wifiicon="$(awk '/^\s*w/ { print "πŸ“Ά", int($3 * 100 / 70) "% " }' /proc/net/wireless)" ;; +esac + +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/.local/bin/statusbar/sb-iplocate b/.local/bin/statusbar/sb-iplocate new file mode 100755 index 0000000..02adab8 --- /dev/null +++ b/.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/.local/bin/statusbar/sb-kbselect b/.local/bin/statusbar/sb-kbselect new file mode 100755 index 0000000..71ffbf1 --- /dev/null +++ b/.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:-i3blocks}";; + 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/.local/bin/statusbar/sb-memory b/.local/bin/statusbar/sb-memory new file mode 100755 index 0000000..01d3daf --- /dev/null +++ b/.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/.local/bin/statusbar/sb-moonphase b/.local/bin/statusbar/sb-moonphase new file mode 100755 index 0000000..fab8b4d --- /dev/null +++ b/.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/.local/bin/statusbar/sb-mpdup b/.local/bin/statusbar/sb-mpdup new file mode 100755 index 0000000..4599344 --- /dev/null +++ b/.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:-i3blocks}")" || break +done diff --git a/.local/bin/statusbar/sb-music b/.local/bin/statusbar/sb-music new file mode 100755 index 0000000..de2cf36 --- /dev/null +++ b/.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 ' ' -| awk '{ if($0>0) print "🎢 " $0}';} + +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/.local/bin/statusbar/sb-nettraf b/.local/bin/statusbar/sb-nettraf new file mode 100755 index 0000000..eb7a73b --- /dev/null +++ b/.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=${XDG_CACHE_HOME:-$HOME/.cache}/${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) $(numfmt --to=iec $tx) diff --git a/.local/bin/statusbar/sb-news b/.local/bin/statusbar/sb-news new file mode 100755 index 0000000..a92733e --- /dev/null +++ b/.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/.local/bin/statusbar/sb-pacpackages b/.local/bin/statusbar/sb-pacpackages new file mode 100755 index 0000000..37ebed3 --- /dev/null +++ b/.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/.local/bin/statusbar/sb-popupgrade b/.local/bin/statusbar/sb-popupgrade new file mode 100755 index 0000000..eab70f8 --- /dev/null +++ b/.local/bin/statusbar/sb-popupgrade @@ -0,0 +1,10 @@ +#!/bin/sh + +printf "Beginning upgrade.\\n" + +yay -Syu + +printf "\\nUpgrade complete.\\nPress to exit window.\\n\\n" +read -r _ + +i3 restart diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price new file mode 100755 index 0000000..35b072f --- /dev/null +++ b/.local/bin/statusbar/sb-price @@ -0,0 +1,38 @@ +#!/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 +interval="@14d" # History contained in chart preceded by '@' (7d = 7 days) +dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices" +pricefile="$dir/$1" +chartfile="$dir/$1-chart" + +updateprice() { ping -q -c 1 example.org >/dev/null 2>&1 && + curl -s "rate.sx/1$1" > "$pricefile" && + curl -s "rate.sx/$1$interval" > "$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 + +printf "$3$%0.2f" "$(cat "$pricefile")" diff --git a/.local/bin/statusbar/sb-tasks b/.local/bin/statusbar/sb-tasks new file mode 100755 index 0000000..586300e --- /dev/null +++ b/.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/.local/bin/statusbar/sb-torrent b/.local/bin/statusbar/sb-torrent new file mode 100755 index 0000000..6527005 --- /dev/null +++ b/.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/.local/bin/statusbar/sb-volume b/.local/bin/statusbar/sb-volume new file mode 100755 index 0000000..61588c3 --- /dev/null +++ b/.local/bin/statusbar/sb-volume @@ -0,0 +1,28 @@ +#!/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" -lt "30" ]; then + icon="πŸ”ˆ" +else + icon="πŸ”‰" +fi + +echo "$icon$vol%" diff --git a/.local/bin/sysact b/.local/bin/sysact new file mode 100755 index 0000000..c7d84b5 --- /dev/null +++ b/.local/bin/sysact @@ -0,0 +1,19 @@ +#!/bin/sh + +# A dmenu wrapper script for system functions. + +# For non-systemd init systems. +case "$(readlink -f /sbin/init)" in + *runit*) hib="doas_askpass zzz" ;; + *openrc*) hib="loginctl suspend" ; reb="loginctl reboot"; shut="loginctl poweroff";; +esac + +cmds="\ +πŸ”’ lock slock +🐻 hibernate ${hib:-doas_askpass systemctl suspend} +πŸ”ƒ reboot ${reb:-doas_askpass reboot} +πŸ–₯ shutdown ${shut:-doas_askpass shutdown -h now}" + +choice="$(echo "$cmds" | cut -d' ' -f 1 | dmenu)" || exit 1 + +`echo "$cmds" | grep "^$choice " | cut -d ' ' -f2-` diff --git a/.local/bin/td-toggle b/.local/bin/td-toggle new file mode 100755 index 0000000..f10ca96 --- /dev/null +++ b/.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 "tranmission-daemon enabled." +fi +sleep 3 && pkill -RTMIN+7 "${STATUSBAR:-dwmblocks}" diff --git a/.local/bin/unmounter b/.local/bin/unmounter new file mode 100755 index 0000000..7f1dbf5 --- /dev/null +++ b/.local/bin/unmounter @@ -0,0 +1,28 @@ +#!/bin/sh + +# Unmount USB drives or Android phones. Replaces the older `dmenuumount`. Fewer +# prompt and also de-decrypts LUKS drives that are unmounted. + +set -e + +mounteddroids="$(grep simple-mtpfs /etc/mtab | awk '{print "πŸ“±" $2}')" +lsblkoutput="$(lsblk -nrpo "name,type,size,mountpoint")" +mounteddrives="$(echo "$lsblkoutput" | awk '($2=="part"||$2="crypt")&&$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "πŸ’Ύ%s (%s)\n",$4,$3}')" + +allunmountable="$(echo "$mounteddroids +$mounteddrives" | sed "/^$/d;s/ *$//")" +test -n "$allunmountable" + +chosen="$(echo "$allunmountable" | dmenu -i -p "Unmount which drive?")" +chosen="${chosen%% *}" +test -n "$chosen" + +sudo -A umount -l "/${chosen#*/}" +notify-send "Device unmounted." "$chosen has been unmounted." + +# Close the chosen drive if decrypted. +cryptid="$(echo "$lsblkoutput" | grep "/${chosen#*/}$")" +cryptid="${cryptid%% *}" +test -b /dev/mapper/"${cryptid##*/}" +sudo -A cryptsetup close "$cryptid" +notify-send "πŸ”’Device dencryption closed." "Drive is now securely locked again." diff --git a/.local/src/dmenu b/.local/src/dmenu new file mode 160000 index 0000000..3a6bc67 --- /dev/null +++ b/.local/src/dmenu @@ -0,0 +1 @@ +Subproject commit 3a6bc67fbd6df190b002d33f600a6465cad9cfb8 diff --git a/.local/src/st b/.local/src/st new file mode 160000 index 0000000..13b3c63 --- /dev/null +++ b/.local/src/st @@ -0,0 +1 @@ +Subproject commit 13b3c631be13849cd80bef76ada7ead93ad48dc6