feat: move ~/bin to ~/.local/bin

This commit is contained in:
AngeD 2022-11-14 15:51:31 +01:00
parent a65adc368b
commit b3b3435a9e
14 changed files with 7 additions and 7 deletions

116
.local/bin/dkprune Executable file
View file

@ -0,0 +1,116 @@
#!/bin/bash
function usage() {
cat << EOF
Usage: $0 [-hcCviIna]
Prune Docker resources.
If no option provided, defaults to -Cvn
Options:
-h Show this help and exits
-c Remove stopped containers
-C Remove all containers
-v Remove unused volumes
-i Remove build images
-I Remove unused images
-n Remove unused networks
-a All of the above, equivalent of -CvIn
EOF
exit 0
}
function add_opt() {
local RESULT
RESULT="$1"
for o in "$@"; do
if [ "$((RESULT & o))" == 0 ]; then
RESULT="$((RESULT + o))"
fi
done
echo "$RESULT"
}
if ! [ -w "/var/run/docker.sock" ] && [ "$EUID" != 0 ]; then
exec sudo -- "$0" "$@"
fi
c=1
C=2
v=4
i=8
# I=16
n=32
# a="$((c + C + v + I + n))"
CLEAN=0
while getopts hcCviIna o; do
case "$o" in
h)
usage
;;
c)
CLEAN="$(add_opt "$CLEAN" "$c")"
;;
C)
CLEAN="$(add_opt "$CLEAN" "$C")"
;;
v)
CLEAN="$(add_opt "$CLEAN" "$v")"
;;
i)
CLEAN="$(add_opt "$CLEAN" "$i")"
;;
I)
CLEAN="$(add_opt "$CLEAN" "$i")"
IMG_OPT="-a"
;;
n)
CLEAN="$(add_opt "$CLEAN" "$n")"
;;
a)
CLEAN="$(add_opt "$CLEAN" "$c" "$C" "$v" "$i" "$n")"
IMG_OPT="-a"
;;
*)
exit 1
;;
esac
done
if [ "$CLEAN" == 0 ]; then
CLEAN="$((C + v + n))"
fi
VALUES=(
"$((c + i + v + n))"
"$((c + i + n))"
"$c"
"$v"
"$i"
"$n"
)
CON="container"
PRUNE="prune -f"
COMMANDS=(
"docker system $PRUNE $IMG_OPT --volumes"
"docker system $PRUNE $IMG_OPT"
"docker $CON $PRUNE"
"docker volume $PRUNE"
"docker image $PRUNE $IMG_OPT"
"docker network $PRUNE"
)
if [ "$((CLEAN & "$C"))" == "$C" ]; then
docker "$CON" ls -aq | xargs docker "$CON" stop 2> /dev/null
CLEAN="$(add_opt "$CLEAN" "$c")"
fi
for idx in "${!VALUES[@]}"; do
mask="${VALUES[$idx]}"
if [ "$((CLEAN & mask))" == "$mask" ]; then
bash -c "${COMMANDS[$idx]}"
CLEAN="$((CLEAN - mask))"
fi
done

9
.local/bin/mouse_360 Executable file
View file

@ -0,0 +1,9 @@
#!/bin/bash
set -e
# counts target = 8182 ~ 25cm
sleep 3
for _ in {0..1023}; do
xdotool mousemove_relative 8 0
done

17
.local/bin/scanpdf Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
set -e
usage() {
echo "USAGE: $0 FILE.pdf"
exit 0
}
if [ "$1" == '-h' ] || [[ "$1" != *.pdf ]]; then
usage
fi
DEVICE='pixma:04A9178A_31A16C'
FORMAT='png'
RES=300
scanimage -d "$DEVICE" --format="$FORMAT" --resolution "$RES" | convert - "$1"

10
.local/bin/set-ddc-light Executable file
View file

@ -0,0 +1,10 @@
#!/bin/bash
set -e
CUR_LIGHT="$(set-light "$@")"
SCREENS="$(sudo ddcutil detect | awk '$1 == "Display" {print $2}')"
for i in $SCREENS; do
sudo ddcutil -d "$i" setvcp 10 "$CUR_LIGHT"
done

43
.local/bin/set-light Executable file
View file

@ -0,0 +1,43 @@
#!/bin/bash
set -e
shopt -s extglob nullglob
set_brightness() {
MAX="$(cat "$1"/max_brightness)"
FILE="$1"/brightness
VAL="$(($2 * MAX / 100 + 1))"
[ "$VAL" -lt 0 ] && VAL=0
[ "$VAL" -gt "$MAX" ] && VAL="$MAX"
echo "$VAL" > "$FILE"
}
CUR_FILE=/var/tmp/current_brightness
set +e
CUR="$(cat "$CUR_FILE" || echo 50)"
set -e
CUR="$((CUR - CUR % "$1"))"
case "${1:0:1}" in
'')
exit 1
;;
'+'|'-')
NEW="$((CUR + "$1"))"
;;
*)
NEW="$1"
;;
esac
[ "$NEW" -lt 0 ] && NEW=0
[ "$NEW" -gt 100 ] && NEW=100
for dev in /sys/class/backlight/*; do
set_brightness "$dev" "$NEW"
done
echo "$NEW" > "$CUR_FILE"
echo "$NEW"

47
.local/bin/set-vol Executable file
View file

@ -0,0 +1,47 @@
#!/bin/bash
set -e
# TODO: multiple fast invocation cause volume not to be updated
PACTL_SINK='@DEFAULT_SINK@'
SINK="$PACTL_SINK"
function get_vol() {
VOL="$(pactl get-sink-volume "$SINK" 2> /dev/null)"
if [ -n "$VOL" ]; then
CMD='pactl set-sink-volume'
else
CMD='amixer sset'
SINK='Master'
VOL="$(amixer sget "$SINK")"
fi
}
set +e
get_vol
set -e
VOL="$(echo "$VOL" | grep -Po '\d+(?=%)' | head -n 1)"
VOL="$((VOL - VOL % "$1"))"
case "${1:0:1}" in
'')
exit 1
;;
'+'|'-')
VOL="$((VOL + "$1"))"
;;
*)
VOL="$1"
;;
esac
[ "$VOL" -lt 0 ] && VOL=0
[ "$VOL" -gt 100 ] && VOL=100
$CMD "$SINK" "$VOL%" > /dev/null
pactl set-sink-mute "$PACTL_SINK" 0
echo "$VOL"

19
.local/bin/ttydestroyer Executable file
View file

@ -0,0 +1,19 @@
#!/bin/bash
usage() {
echo "Usage: $0 /dev/pts/{tty_nb}"
exit 0
}
if [ -z "$1" ]; then
set "$(tty)"
elif ! [ -w "$1" ]; then
usage
fi
(set -e
asciiquarium &
cmatrix -ab &
while true; do sl; done &
) | lolcat > "$1"