From bd88099e12e5781e9f38d2af17ab829e80e30687 Mon Sep 17 00:00:00 2001 From: dwalker Date: Sat, 2 May 2026 22:14:30 -0400 Subject: reworked scripts --- .script/bootstrapxbps | 75 ----------------------------------------- .script/bootstrapxbps.sh | 75 +++++++++++++++++++++++++++++++++++++++++ .script/dwmstatus | 79 -------------------------------------------- .script/favs_dmenu_run.sh | 14 ++++++++ .script/gpu_usage_nvidia.sh | 9 +++++ .script/refreshstatus | 5 --- .script/weather | 2 -- .script/weather.sh | 2 ++ .script/xbps_update_count.sh | 8 +++++ 9 files changed, 108 insertions(+), 161 deletions(-) delete mode 100755 .script/bootstrapxbps create mode 100755 .script/bootstrapxbps.sh delete mode 100755 .script/dwmstatus create mode 100755 .script/favs_dmenu_run.sh create mode 100755 .script/gpu_usage_nvidia.sh delete mode 100755 .script/refreshstatus delete mode 100755 .script/weather create mode 100755 .script/weather.sh create mode 100755 .script/xbps_update_count.sh (limited to '.script') diff --git a/.script/bootstrapxbps b/.script/bootstrapxbps deleted file mode 100755 index 310327c..0000000 --- a/.script/bootstrapxbps +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/sh -# -# bootstrapxbps -# -# This script takes a comma separated .csv file with the following format: -# A,B,C,... -# where: -# A = an xbps package name. -# all other columns will be ignored. -# -# First, "xbps-install -Suvy" will be called 3 times to ensure up to date repositories and existing packages. -# Then, all A values will be put into a call to "xbps-install". - -Help() -{ - echo "bootstrapxbps [-h] [-e] file.csv" - echo "file.csv is a comma separated value file. Separate with ," - echo "Package names will be gathered from the 0th column." - echo "-h Help" - echo "-e Install nonfree and multilib repositories before bootstrap" -} - -Usage() -{ - echo "Usage:" - echo "bootstrapxbps -h" - echo "bootstrapxbps [-e] file.csv" -} - -ExtraRepos() -{ - # Install multilib repository separately. - xbps-install -Sy void-repo-multilib - xbps-install -Sy void-repo-multilib-nonfree - xbps-install -Sy void-repo-nonfree -} - -Upgrade() -{ - # Update repositories and existing packages. - xbps-install -Suy - xbps-install -Suy - xbps-install -Suy - - # Gather packages in .csv argument. - IFS="," - CMD="xbps-install" - - while read package comment; do - CMD="${CMD} ${package}" - done < "${1}" - - IFS=$OLDIFS - - # Install specified packages. - eval $CMD - - exit 0 -} - -while getopts 'he' c; do - case ${c} in - h) Help - exit 0 - ;; - e) ExtraRepos - ;; - \?) Usage - exit 1 - ;; - esac -done -shift $((OPTIND -1)) - -Upgrade $1 diff --git a/.script/bootstrapxbps.sh b/.script/bootstrapxbps.sh new file mode 100755 index 0000000..310327c --- /dev/null +++ b/.script/bootstrapxbps.sh @@ -0,0 +1,75 @@ +#!/bin/sh +# +# bootstrapxbps +# +# This script takes a comma separated .csv file with the following format: +# A,B,C,... +# where: +# A = an xbps package name. +# all other columns will be ignored. +# +# First, "xbps-install -Suvy" will be called 3 times to ensure up to date repositories and existing packages. +# Then, all A values will be put into a call to "xbps-install". + +Help() +{ + echo "bootstrapxbps [-h] [-e] file.csv" + echo "file.csv is a comma separated value file. Separate with ," + echo "Package names will be gathered from the 0th column." + echo "-h Help" + echo "-e Install nonfree and multilib repositories before bootstrap" +} + +Usage() +{ + echo "Usage:" + echo "bootstrapxbps -h" + echo "bootstrapxbps [-e] file.csv" +} + +ExtraRepos() +{ + # Install multilib repository separately. + xbps-install -Sy void-repo-multilib + xbps-install -Sy void-repo-multilib-nonfree + xbps-install -Sy void-repo-nonfree +} + +Upgrade() +{ + # Update repositories and existing packages. + xbps-install -Suy + xbps-install -Suy + xbps-install -Suy + + # Gather packages in .csv argument. + IFS="," + CMD="xbps-install" + + while read package comment; do + CMD="${CMD} ${package}" + done < "${1}" + + IFS=$OLDIFS + + # Install specified packages. + eval $CMD + + exit 0 +} + +while getopts 'he' c; do + case ${c} in + h) Help + exit 0 + ;; + e) ExtraRepos + ;; + \?) Usage + exit 1 + ;; + esac +done +shift $((OPTIND -1)) + +Upgrade $1 diff --git a/.script/dwmstatus b/.script/dwmstatus deleted file mode 100755 index 9f288e1..0000000 --- a/.script/dwmstatus +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/sh - -# This script sets the statusbar with the xsetroot command at the end. -# Call it inside ~/.xinitrc or ~/.xprofile. - -# Handle SIGTRAP signals sent by refbar to update the status bar immediately. -trap 'update' 5 - -# Set the deliminter character. -delim="|" - -# testweather checks to see if the most recent forecast is up to date. If it isnt' it -# downloads a new weather forecast, then signals to update the statusbar. Gets weather report from wttr.in. -testweather() { \ - [ "$(stat -c %y "$HOME/.local/share/weatherreport" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] && - ping -q -c 1 1.1.1.1 >/dev/null && - curl -s "wttr.in/$location" > "$HOME/.local/share/weatherreport" && - notify-send "🌞 Weather" "New weather forecast for today." && - $HOME/.script/refreshstatus -} - -# Here is the cumulative function that outputs and formats the appearance of the statusbar. -# It can really be broken down into many submodules which are commented and explained. -status() { \ - # Get current mpd track filename or artist - title if possible. - mpc -f "[[%artist% - ]%title%]|[%file%]" 2>/dev/null | grep -v "volume:" | head -n 1 && echo "$delim" - - # If the weather report is current, show daily precipitation chance, low and high. - # Takes the weather report from wttr.in and formats it for the status bar. - [ "$(stat -c %y "$HOME/.local/share/weatherreport" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] && - sed '16q;d' "$HOME/.local/share/weatherreport" | grep -wo "[0-9]*%" | sort -n | sed -e '$!d' | sed -e "s/^/ /g" | tr -d '\n' && - sed '13q;d' "$HOME/.local/share/weatherreport" | grep -o "m\\(-\\)*[0-9]\\+" | sort -n -t 'm' -k 2n | sed -e 1b -e '$!d' | tr '\n|m' ' ' | awk '{print " ",$1 "°","",$2 "°"}' && - echo "$delim" - - # Get the volume of ALSA's master volume output. Show an icon if or not muted. - amixer get Master | grep -o "[0-9]*%\|\[on\]\|\[off\]" | sed "s/\[on\]//;s/\[off\]//" - - echo "$delim" - - # Wifi quality percentage and icon if ethernet is connected. - grep "^\s*w" /proc/net/wireless | awk '{ print "", int($3 * 100 / 70) "%" }' - sed "s/down//;s/up//" /sys/class/net/e*/operstate - - # Will show all batteries with approximate icon for remaining power. - for x in /sys/class/power_supply/BAT?/capacity; - do - case "$(cat $x)" in - 100|9[0-9]) echo "" ;; - 8[0-9]|7[0-9]) echo "" ;; - 6[0-9]|5[0-9]) echo "" ;; - 4[0-9]|3[0-9]) echo "" ;; - *) echo "" ;; - esac - done && echo "$delim" - - # Date and time. - date '+%Y %b %d (%a) %I:%M%p' -} - -update() { \ - # Have xsetroot set dwm status bar with our formatted input. - # Note that the tr command replaces newlines with spaces. This is - # to prevent some weird issues that cause significant slowing of - # everything in dwm. Cause unknown. - xsetroot -name "$(status | tr '\n' ' ')" & wait - - # Check to see if new weather report is needed. - testweather & wait -} - -while :; do - update - # Sleep for a minute after changing the status bar before updating it - # again. We run sleep in the background and use wait until it finishes, - # because traps can interrupt wait immediately, but they can't do that with sleep. - sleep 1m & - wait -done - diff --git a/.script/favs_dmenu_run.sh b/.script/favs_dmenu_run.sh new file mode 100755 index 0000000..7a927a1 --- /dev/null +++ b/.script/favs_dmenu_run.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +favorites=' +chromium +discord +firefox +steam +' + +{ + printf '%s\n' "$favorites" + dmenu_path +} | awk '!seen[$0]++' | dmenu "$@" | ${SHELL:-/bin/sh} & + diff --git a/.script/gpu_usage_nvidia.sh b/.script/gpu_usage_nvidia.sh new file mode 100755 index 0000000..7bd1c54 --- /dev/null +++ b/.script/gpu_usage_nvidia.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +out=$(nvidia-smi -i 0 --query-gpu=utilization.gpu,memory.used --format=csv,noheader,nounits 2>/dev/null) || exit 0 + +gpu=$(printf "%s" "$out" | awk -F',' '{gsub(/ /,"",$1); print $1}') +mem=$(printf "%s" "$out" | awk -F',' '{gsub(/ /,"",$2); print $2}') + +# mem is in MiB from nvidia-smi; display as M for brevity. +printf "VRAM %sM|GPU %s%%\n" "$mem" "$gpu" > /tmp/gpu_usage diff --git a/.script/refreshstatus b/.script/refreshstatus deleted file mode 100755 index 5d8c5ec..0000000 --- a/.script/refreshstatus +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -# Refresh dwm status. -# Send SIGTRAP signal to dwmstatus script, which will handle it with a trap. -pkill -SIGTRAP dwmbar diff --git a/.script/weather b/.script/weather deleted file mode 100755 index 91634c5..0000000 --- a/.script/weather +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -curl -s wttr.in/?format="%l:+%C+%t" > /tmp/weather diff --git a/.script/weather.sh b/.script/weather.sh new file mode 100755 index 0000000..91634c5 --- /dev/null +++ b/.script/weather.sh @@ -0,0 +1,2 @@ +#!/bin/sh +curl -s wttr.in/?format="%l:+%C+%t" > /tmp/weather diff --git a/.script/xbps_update_count.sh b/.script/xbps_update_count.sh new file mode 100755 index 0000000..1df8aa6 --- /dev/null +++ b/.script/xbps_update_count.sh @@ -0,0 +1,8 @@ +#!/bin/sh +count=$(xbps-install -Mun 2>/dev/null | wc -l) + +if [ "$count" -eq 0 ]; then + echo "XBPS: up to date" > /tmp/xbps_update_count +else + echo "XBPS: $count available" > /tmp/xbps_update_count +fi -- cgit v1.2.3