feat: huge update

This commit is contained in:
ange 2024-10-01 13:47:31 +07:00
parent 9c621760cf
commit 757b759b4a
Signed by: ange
GPG key ID: 9E0C4157BB7BEB1D
47 changed files with 221 additions and 286 deletions

View file

@ -17,7 +17,7 @@ def get_btc_fees() -> str:
url = "mempool.space"
path = "/api/v1/fees/mempool-blocks"
client = http.HTTPSConnection(url)
client = http.HTTPSConnection(url, timeout=10)
client.request("GET", path)
# https://mempool.space/docs/api/rest#get-mempool-blocks-fees
@ -30,7 +30,7 @@ def get_coins_values() -> str:
url = "api.coingecko.com"
path = f"/api/v3/simple/price?ids={ids}&vs_currencies={CURRENCY}"
client = http.HTTPSConnection(url)
client = http.HTTPSConnection(url, timeout=10)
client.request("GET", path)
# https://www.coingecko.com/api/documentation

View file

@ -1,27 +0,0 @@
#!/bin/bash -e
OPT=()
if [ -z "$WAYLAND_DISPLAY" ]; then
OPT+=(
--network=host
-e XAUTHORITY=/app/.Xauthority
-v "$XAUTHORITY:/app/.Xauthority:ro"
)
fi
podman run --rm -it --name epitest \
"${OPT[@]}" \
--ipc=host \
--device /dev/dri/ \
-e DISPLAY \
-e XDG_RUNTIME_DIR \
-e MAKEFLAGS \
-e CFLAGS=-g3 \
-e CXXFLAGS=-g3 \
-v /tmp/.X11-unix/:/tmp/.X11-unix/ \
-v "$XDG_RUNTIME_DIR:$XDG_RUNTIME_DIR" \
-v /usr/share/fonts/:/usr/share/fonts/:ro \
-v "$PWD:$PWD" \
-w "$PWD" \
docker.io/epitechcontent/epitest-docker:latest \
"$@"

19
.local/bin/ffreduce Executable file
View file

@ -0,0 +1,19 @@
#!/bin/bash -e
in="$1"; shift
out="$1"; shift
smalside="${1:-480}"; shift || true
if ! [ -r "$in" ]; then
echo "error: can't read '$in'" >&2
exit 1
fi
if [ -z "$out" ]; then
echo "error: output file name can't be empty" >&2
exit 1
fi
set -x
#ffmpeg -i "$in" -r 24 -vcodec libx265 -vf "scale=-2:$smalside,setpts=0.5*PTS" "$@" "$out"
ffmpeg -i "$in" -r 24 -vcodec libx265 -vf "scale=-2:$smalside" "$@" "$out"

View file

@ -1,9 +0,0 @@
#!/bin/bash -e
if ! [ -f /tmp/gradle ]; then
podman run -d --rm --name gradle -v "$HOME:$HOME" -w "$PWD" \
docker.io/gradle:8 sleep infinity
touch /tmp/gradle
fi
podman exec -it gradle gradle "$@"

View file

@ -17,8 +17,6 @@ function set_light() {
DIRS=(/sys/class/backlight/*)
CUR="$(get_current "${DIRS[0]}")"
echo "$CUR"
echo "\$(($CUR + $1 - $CUR % $1 + $CUR % $1 / $1 * $1))"
case "${1:0:1}" in
'') echo "$CUR"; exit ;;
'+'|'-') CUR="$(($CUR + $1 - $CUR % $1 + $CUR % $1 * 10 / $1 / 5 * $1))" ;;
@ -32,6 +30,3 @@ echo "$CUR"
for d in "${DIRS[@]}"; do
set_light "$d"
done
notify-send -t 1000 -u low -i display-brightness-symbolic \
-h string:synchronous:light -h int:value:"$CUR" "$CUR%"

View file

@ -52,20 +52,28 @@ function update_source_vol() {
source_vol=" $(awk '{printf "%.0f", $2 * 100}' <<< "$source")"
}
function update_wlp() {
local sig ssid dev=wlan0
function update_net() {
local dev j ssid sig
sig="$(awk "/$dev/{printf \"%.0f\", \$3}" /proc/net/wireless)"
if [ -z "$sig" ]; then
wlp='⚠'
return
fi
ssid="$(networkctl status "$dev" --json=short | jq -r .SSID)"
{ [ "$sig" -gt 56 ] && wlp="▂▄▆█ $ssid"; } ||
{ [ "$sig" -gt 38 ] && wlp="▂▄▆_ $ssid"; } ||
{ [ "$sig" -gt 21 ] && wlp="▂▄__ $ssid"; } ||
{ [ "$sig" -gt 3 ] && wlp="▂___ $ssid"; } ||
{ wlp="____ $ssid"; }
dev="$(ip route show default | sed -n 's/.*dev\s\+\(\w\+\).*/\1/p;q')"
j="$(networkctl status "$dev" --json=short)"
case "$(jq -r .Type <<< "$j")" in
ether)
net="🌐 $dev"
;;
wlan)
ssid="$(jq -r .SSID <<< "$j")"
sig="$(awk "/$dev/{printf \"%.0f\", \$3}" /proc/net/wireless)"
{ [ "$sig" -gt 56 ] && net="▂▄▆█ $ssid"; } ||
{ [ "$sig" -gt 38 ] && net="▂▄▆_ $ssid"; } ||
{ [ "$sig" -gt 21 ] && net="▂▄__ $ssid"; } ||
{ [ "$sig" -gt 3 ] && net="▂___ $ssid"; } ||
{ net="____ $ssid"; }
;;
*)
net='⚠'
;;
esac
}
function update_time() {
@ -77,7 +85,7 @@ function reload() {
}
function display() {
"${DISPLAYCMD[@]}" "$crypto | $cpu | $memory | $sink_vol $source_vol | $wlp | $bat | $time"
"${DISPLAYCMD[@]}" "$crypto | $cpu | $memory | $sink_vol $source_vol | $net | $bat | $time"
}
if [ "$XDG_SESSION_TYPE" = wayland ]; then
@ -87,10 +95,11 @@ else
fi
# SIGNALING
# trap '<function>;display;wait' 'RTMIN+n'
trap 'reload' 'RTMIN'
trap 'update_sink_vol;display;wait' 'RTMIN+1'
trap 'update_wlp;display;wait' 'RTMIN+2'
# trap '<function>;display;wait' 'RTMIN+n'
trap 'reload' 'RTMIN'
trap 'update_sink_vol;display;wait' 'RTMIN+1'
trap 'update_source_vol;display;wait' 'RTMIN+2'
trap 'update_net;display;wait' 'RTMIN+3'
# to update it from external commands
## kill -m "$(cat ~/.cache/pidofbar)"
# where m = 34 + n
@ -105,12 +114,12 @@ while true; do
update_memory
update_sink_vol
update_source_vol
update_wlp
update_net
update_bat
update_time
display
}
sec="$((sec + 10))"
((sec += 10))
awk "@load \"time\"; BEGIN {d=10; s=$(date '+%S.%N'); sleep(d - s % d)}" &
wait
done

View file

@ -1,3 +0,0 @@
#!/bin/bash
com.valvesoftware.Steam --nobrowser

View file

@ -1,34 +1,46 @@
#!/bin/bash -e
SINK='@DEFAULT_AUDIO_SINK@'
NOTIFY=(notify-send -t 1000 -u low)
case "$1" in
s)
DEV='@DEFAULT_AUDIO_SINK@'
SIG=35
;;
m)
DEV='@DEFAULT_AUDIO_SOURCE@'
SIG=36
;;
*)
exit 1
;;
esac
shift
function update_vol() {
if [[ "$1" =~ ^(-|\+)* ]]; then
CUR="$(($CUR + $1 - $CUR % $1 + $CUR % $1 * 10 / $1 / 5 * $1))"
[ "$CUR" -lt 0 ] && CUR=0
[ "$CUR" -gt 150 ] && CUR=150
else
CUR="$1"
fi
wpctl set-volume "$SINK" "$CUR%"
case "$1" in
+*|-*)
CUR="$(($CUR + $1 - $CUR % $1 + $CUR % $1 * 10 / $1 / 5 * $1))"
[ "$CUR" -lt 0 ] && CUR=0
[ "$CUR" -gt 200 ] && CUR=200
;;
*)
CUR="$1"
esac
wpctl set-volume "$DEV" "$CUR%"
}
read -r _ CUR MUTE < <(wpctl get-volume "$SINK")
read -r _ CUR MUTE < <(wpctl get-volume "$DEV")
CUR="$(("10#${CUR/./}"))"
if [ -z "$1" ]; then
echo "$CUR"
exit
elif [ "$1" == 'm' ] && [ -z "$MUTE" ]; then
wpctl set-mute "$SINK" 1
"${NOTIFY[@]}" -i audio-volume-muted-symbolic -h string:synchronous:vol "Mute"
wpctl set-mute "$DEV" 1
else
if [[ "$1" =~ [0-9] ]]; then
update_vol "$1"
fi
[ -n "$MUTE" ] && wpctl set-mute "$SINK" 0
"${NOTIFY[@]}" -i audio-volume-high-symbolic -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"
[ -n "$MUTE" ] && wpctl set-mute "$DEV" 0
fi
kill -35 "$(cat "$HOME/.cache/pidofbar")"
kill "-$SIG" "$(cat "$HOME/.cache/pidofbar")"

View file

@ -2,11 +2,12 @@
iwctl=(iwctl station wlan0)
rfkill unblock wlan
"${iwctl[@]}" show | grep -q 'Scanning\s\+yes' || "${iwctl[@]}" scan
for _ in {0..29}; do
if "${iwctl[@]}" show | grep -q '\s*State\s\+connected\s*$'; then
kill -36 "$(cat "$HOME/.cache/pidofbar")"
kill -37 "$(cat "$HOME/.cache/pidofbar")"
exit 0
fi
sleep 1