script changes hell

This commit is contained in:
frosty 2024-07-03 19:59:32 -04:00
parent c42ba15500
commit 0beda2cf99
15 changed files with 181 additions and 58 deletions

16
.local/bin/batmon Executable file
View file

@ -0,0 +1,16 @@
#!/bin/sh
FULL_THRESHOLD=80
FULL_COLOR="#31f53e"
read -r capacity </sys/class/power_supply/BAT1/capacity
read -r status </sys/class/power_supply/BAT1/status
if [ "$capacity" -ge "$FULL_THRESHOLD" ] && [ "$status" = "Not charging" ]; then
status="Full"
fi
if [ "$status" = "Full" ]; then
printf '<fc=%s>%s%%</fc> (%s)\n' "$FULL_COLOR" "$capacity" "$status"
else
printf '%s%% (%s)\n' "$capacity" "$status"
fi

View file

@ -1,14 +1,29 @@
#!/bin/sh #!/bin/sh
initial_values=$(awk '/cpu /{print $2+$4,$2+$4+$5}' /proc/stat) while read -r _ user _ system idle _; do
sleep 2 initial_user_sys=$((user + system))
current_values=$(awk '/cpu /{print $2+$4,$2+$4+$5}' /proc/stat) initial_total=$((user + system + idle))
break
done </proc/stat
set -- $initial_values sleep 1
initial_user_sys=$1
initial_total=$2
set -- $current_values
current_user_sys=$1
current_total=$2
awk "BEGIN {print ($current_user_sys - $initial_user_sys) / ($current_total - $initial_total) * 100}" while read -r _ user _ system idle _; do
current_user_sys=$((user + system))
current_total=$((user + system + idle))
break
done </proc/stat
while read -r line; do
case $line in
*Package\ id\ 0:*) temp=$line ;;
esac
done <<EOF
$(sensors)
EOF
temp=${temp#Package id 0:*+}
temp=${temp%%°*}
temp=${temp%.*}
printf '%s°C (%.*f%%)\n' "$temp" 0 $(((current_user_sys - initial_user_sys) * 100 / (current_total - initial_total)))

View file

@ -74,14 +74,20 @@ version() {
} }
while getopts :hVqcos opt; do while getopts :hVqcos opt; do
case "$opt" in case $opt in
h) usage; exit 0 ;; h)
V) version; exit 0 ;; usage
q) QUIET=1 ;; exit 0
c) COPY=1 ;; ;;
o) OVERLAY=1 ;; V)
s) SAVE=1 ;; version
*) die "invalid option: -$OPTARG" ;; exit 0
;;
q) QUIET=1 ;;
c) COPY=1 ;;
o) OVERLAY=1 ;;
s) SAVE=1 ;;
*) die "invalid option: -$OPTARG" ;;
esac esac
done done
@ -91,8 +97,11 @@ SCREENSHOT_TYPE=${1:-select}
FILE_PATH=${2:-} FILE_PATH=${2:-}
case "$SCREENSHOT_TYPE" in case "$SCREENSHOT_TYPE" in
select|full) ;; select | full) ;;
*) usage; exit 1 ;; *)
usage
exit 1
;;
esac esac
if [ -n "$SAVE" ]; then if [ -n "$SAVE" ]; then

View file

@ -1,10 +1,10 @@
#!/bin/sh #!/bin/sh
LOW_USED_COLOR="#b8bb26" LOW_USED_COLOR="#a3be8c"
MEDIUM_USED_COLOR="#fabd2f" MEDIUM_USED_COLOR="#ebcb8b"
HIGH_USED_COLOR="#fb4934" HIGH_USED_COLOR="#bf616a"
DEFAULT_USED_COLOR="#d5c4a1" DEFAULT_USED_COLOR="#81a1c1"
UNUSED_COLOR="#a88984" UNUSED_COLOR="#5e81ac"
usage=$1 usage=$1
width=$2 width=$2
@ -14,26 +14,43 @@ command -v "$1" >/dev/null && usage=$($1)
low_used=$((width * 30 / 100)) low_used=$((width * 30 / 100))
medium_used=$((width * 60 / 100)) medium_used=$((width * 60 / 100))
num_used_chars=$(echo "scale=0; ($usage * $width) / 100" | bc -l) num_used_chars=$(printf 'scale=0; (%s * %s) / 100\n' "$usage" "$width" | bc -l)
if [ -n "$usage_color" ]; then if [ -n "$usage_color" ]; then
case "$num_used_chars" in case "$num_used_chars" in
[0-$low_used]) used_color="$LOW_USED_COLOR" ;; [0-$low_used]) used_color="$LOW_USED_COLOR" ;;
[$low_used-$medium_used]) used_color="$MEDIUM_USED_COLOR" ;; [$low_used-$medium_used]) used_color="$MEDIUM_USED_COLOR" ;;
*) used_color="$HIGH_USED_COLOR" ;; *) used_color="$HIGH_USED_COLOR" ;;
esac esac
else else
used_color="$DEFAULT_USED_COLOR" used_color="$DEFAULT_USED_COLOR"
fi fi
prev_opened=0
any_used_width=0
i=1 i=1
while [ "$i" -le "$width" ]; do while [ "$i" -le "$width" ]; do
if [ "$i" -le "$num_used_chars" ]; then if [ "$i" -le "$num_used_chars" ]; then
bar="$bar<fc=$used_color>#</fc>" if [ "$prev_opened" -eq 0 ]; then
bar="$bar<fc=$used_color>"
prev_opened=1
any_used_width=1
fi
bar="$bar#"
else else
bar="$bar<fc=$UNUSED_COLOR>:</fc>" if [ "$any_used_width" -eq 1 ]; then
bar="$bar</fc>"
prev_opened=0
any_used_width=0
fi
if [ "$prev_opened" -eq 0 ]; then
bar="$bar<fc=$UNUSED_COLOR>"
prev_opened=1
fi
bar="$bar:"
fi fi
i=$((i + 1)) i=$((i + 1))
done done
bar="$bar</fc>"
echo "$bar" printf '%s\n' "$bar"

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
PIPES="nowplaying volume" PIPES="volume"
for pipe in $PIPES; do for pipe in $PIPES; do
echo "" >"/tmp/pipe-$pipe" echo "" >"/tmp/pipe-$pipe"

7
.local/bin/ipmon Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
address=$(ip route get 1)
address=${address#* via * dev * src }
address=${address% uid *}
printf '%s\n' "$address"

9
.local/bin/loadmon Executable file
View file

@ -0,0 +1,9 @@
#!/bin/sh
while read -r one five fifteen _; do
load_one=$one
load_five=$five
load_fifteen=$fifteen
done </proc/loadavg
printf '%s %s %s\n' "$load_one" "$load_five" "$load_fifteen"

View file

@ -1,8 +1,21 @@
#!/bin/sh #!/bin/sh
total_mem=$(($(grep MemTotal /proc/meminfo | awk '{print $2}') / 1024)) convert_to_human_readable() {
free_mem=$(($(grep MemAvailable /proc/meminfo | awk '{print $2}') / 1024)) if [ "$1" -lt 1024 ]; then
printf "%.1fK\n" "$1"
elif [ "$1" -lt 1048576 ]; then
printf "%.1fM\n" $(($1 / 1024))
else
printf "%.1fG\n" $(($1 / 1048576))
fi
}
while read -r label size _; do
case $label in
MemTotal:) total_mem=$size ;;
MemAvailable:) free_mem=$size ;;
esac
done </proc/meminfo
used_mem=$((total_mem - free_mem)) used_mem=$((total_mem - free_mem))
awk "BEGIN {print ($used_mem / $total_mem) * 100}" printf '%s (%s%%)\n' "$(convert_to_human_readable "$used_mem")" $((used_mem * 100 / total_mem))

View file

@ -5,4 +5,4 @@ TEXT_COLOR="#fe8019"
PIPE_FILE="/tmp/pipe-nowplaying" PIPE_FILE="/tmp/pipe-nowplaying"
[ -p "$PIPE_FILE" ] || mkfifo "$PIPE_FILE" [ -p "$PIPE_FILE" ] || mkfifo "$PIPE_FILE"
playerctl metadata --format "<fc=$TEXT_COLOR>{{artist}} - {{title}}</fc>" >"$PIPE_FILE" echo "<fc=$TEXT_COLOR>$(mpc | head -n1)</fc>" >"$PIPE_FILE"

View file

@ -3,5 +3,4 @@
PIPE_FILE="/tmp/pipe-volume" PIPE_FILE="/tmp/pipe-volume"
[ -p "$PIPE_FILE" ] || mkfifo "$PIPE_FILE" [ -p "$PIPE_FILE" ] || mkfifo "$PIPE_FILE"
volume=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '/Volume/ { print int($NF * 100) }') volmon >"$PIPE_FILE"
genbar "$volume" 10 1 >"$PIPE_FILE"

View file

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
xrandr \ xrandr \
--output eDP-1 --off \ --output eDP1 --off \
--output HDMI-2 --primary --mode 1920x1080 --pos 0x0 --rotate normal --output HDMI2 --primary --mode 1920x1080 --pos 0x0 --rotate normal

17
.local/bin/ssidmon Executable file
View file

@ -0,0 +1,17 @@
#!/bin/sh
ADAPTER="wlan0"
ssid=
while read -r line; do
case $line in
*Connected\ network*)
ssid=${line##*Connected network}
ssid="${ssid#"${ssid%%[![:space:]]*}"}"
;;
esac
done <<EOF
$(iwctl station "$ADAPTER" show)
EOF
printf '%s\n' "$ssid"

15
.local/bin/tempmon Executable file
View file

@ -0,0 +1,15 @@
#!/bin/sh
while read -r line; do
case $line in
*Package\ id\ 0:*) temp=$line ;;
esac
done <<EOF
$(sensors)
EOF
temp=${temp#Package id 0:*+}
temp=${temp%%°*}
temp=${temp%.*}
printf '%s°C\n' "$temp"

View file

@ -1,3 +1,9 @@
#!/bin/sh #!/bin/sh
wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '/Volume/ { print int($NF * 100) }' volume=$(wpctl get-volume @DEFAULT_AUDIO_SINK@)
volume=${volume% \[MUTED\]}
volume=${volume#Volume: }
volume=${volume%.*}${volume#*.}
volume=${volume#0}
printf '%s%%\n' "$volume"

View file

@ -39,8 +39,8 @@ restore() {
previous="$(readlink -f "$XDG_DATA_HOME/wallpaper")" previous="$(readlink -f "$XDG_DATA_HOME/wallpaper")"
case "${previous##*.}" in case "${previous##*.}" in
png|jpg|jpeg) ;; png | jpg | jpeg) ;;
*) die "$previous: unsupported file type" ;; *) die "$previous: unsupported file type" ;;
esac esac
cmp -s "$previous" "$XDG_CACHE_HOME/lock.png" || convert_lock "$previous" & cmp -s "$previous" "$XDG_CACHE_HOME/lock.png" || convert_lock "$previous" &
@ -51,24 +51,24 @@ restore() {
while getopts ":hqre:u:" opt; do while getopts ":hqre:u:" opt; do
case $opt in case $opt in
h) usage ;; h) usage ;;
q) QUIET=1 ;; q) QUIET=1 ;;
r) restore ;; r) restore ;;
e) LOCK_RESOLUTION="$OPTARG" ;; e) LOCK_RESOLUTION=$OPTARG ;;
u) LOCK_QUALITY="$OPTARG" ;; u) LOCK_QUALITY=$OPTARG ;;
\?) usage "invalid option -- '$OPTARG'" ;; \?) usage "invalid option -- '$OPTARG'" ;;
:) usage "option requires an argument -- '$OPTARG'" ;; :) usage "option requires an argument -- '$OPTARG'" ;;
esac esac
done done
shift $((OPTIND - 1)) shift $((OPTIND - 1))
if [ "$1" = "-" ]; then if [ "$1" = "-" ]; then
while IFS= read -r line; do while read -r line; do
image="$line" image=$line
done done
else else
image="$1" image=$1
fi fi
[ -n "$image" ] || usage "IMAGE was not provided" [ -n "$image" ] || usage "IMAGE was not provided"
@ -76,8 +76,8 @@ fi
[ -f "$image" ] || die "$image: no such file" [ -f "$image" ] || die "$image: no such file"
case "${image##*.}" in case "${image##*.}" in
png|jpg|jpeg) ;; png | jpg | jpeg) ;;
*) die "$image: unsupported file type" ;; *) die "$image: unsupported file type" ;;
esac esac
cmp -s "$image" "$XDG_CACHE_HOME/lock.png" || convert_lock "$image" & cmp -s "$image" "$XDG_CACHE_HOME/lock.png" || convert_lock "$image" &