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
initial_values=$(awk '/cpu /{print $2+$4,$2+$4+$5}' /proc/stat)
sleep 2
current_values=$(awk '/cpu /{print $2+$4,$2+$4+$5}' /proc/stat)
while read -r _ user _ system idle _; do
initial_user_sys=$((user + system))
initial_total=$((user + system + idle))
break
done </proc/stat
set -- $initial_values
initial_user_sys=$1
initial_total=$2
set -- $current_values
current_user_sys=$1
current_total=$2
sleep 1
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,9 +74,15 @@ version() {
}
while getopts :hVqcos opt; do
case "$opt" in
h) usage; exit 0 ;;
V) version; exit 0 ;;
case $opt in
h)
usage
exit 0
;;
V)
version
exit 0
;;
q) QUIET=1 ;;
c) COPY=1 ;;
o) OVERLAY=1 ;;
@ -92,7 +98,10 @@ FILE_PATH=${2:-}
case "$SCREENSHOT_TYPE" in
select | full) ;;
*) usage; exit 1 ;;
*)
usage
exit 1
;;
esac
if [ -n "$SAVE" ]; then

View file

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

View file

@ -1,6 +1,6 @@
#!/bin/sh
PIPES="nowplaying volume"
PIPES="volume"
for pipe in $PIPES; do
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
total_mem=$(($(grep MemTotal /proc/meminfo | awk '{print $2}') / 1024))
free_mem=$(($(grep MemAvailable /proc/meminfo | awk '{print $2}') / 1024))
convert_to_human_readable() {
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))
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"
[ -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"
[ -p "$PIPE_FILE" ] || mkfifo "$PIPE_FILE"
volume=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '/Volume/ { print int($NF * 100) }')
genbar "$volume" 10 1 >"$PIPE_FILE"
volmon >"$PIPE_FILE"

View file

@ -1,5 +1,5 @@
#!/bin/sh
xrandr \
--output eDP-1 --off \
--output HDMI-2 --primary --mode 1920x1080 --pos 0x0 --rotate normal
--output eDP1 --off \
--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
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

@ -54,8 +54,8 @@ while getopts ":hqre:u:" opt; do
h) usage ;;
q) QUIET=1 ;;
r) restore ;;
e) LOCK_RESOLUTION="$OPTARG" ;;
u) LOCK_QUALITY="$OPTARG" ;;
e) LOCK_RESOLUTION=$OPTARG ;;
u) LOCK_QUALITY=$OPTARG ;;
\?) usage "invalid option -- '$OPTARG'" ;;
:) usage "option requires an argument -- '$OPTARG'" ;;
esac
@ -64,11 +64,11 @@ done
shift $((OPTIND - 1))
if [ "$1" = "-" ]; then
while IFS= read -r line; do
image="$line"
while read -r line; do
image=$line
done
else
image="$1"
image=$1
fi
[ -n "$image" ] || usage "IMAGE was not provided"