feat: bin -> .local/bin, vcs_info untracked

This commit is contained in:
ange 2024-04-24 19:22:30 +02:00
parent af14629939
commit 7c98658d24
Signed by: ange
GPG key ID: 9E0C4157BB7BEB1D
30 changed files with 31 additions and 46 deletions

48
.local/bin/am Executable file
View file

@ -0,0 +1,48 @@
#!/bin/bash -e
# TODO
# mount all partitions by selecting disk
# usage
# support for /mnt
function get_row() {
local row _col
IFS=';' read -rsdR -p $'\e[6n' row _col
echo "${row#??}"
}
ROW="$(($(get_row) + 1))"
function clear_output() {
local row
row="$(get_row)"
for _ in $(seq "$ROW" "$row"); do
printf '\e[1A\e[K'
done
}
function main() {
while true; do
mapfile -t LSBLK <<< "$(lsblk -n --paths --list | grep part)"
COLUMNS=1
select dev in "${LSBLK[@]}"; do
if [ -z "$dev" ]; then
clear_output
break
fi
name="$(awk '{print $1}' <<< "$dev")"
clear_output
if mount | grep -q "$name"; then
umount "$name"
else
udisksctl mount -b "$name" > /dev/null
fi
break
done || exit
done
}
main "$@"

3
.local/bin/arch Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash -e
podman run --rm -it -v "$PWD:/mnt/" -w /mnt/ docker.io/archlinux/archlinux:base

51
.local/bin/crypto Executable file
View file

@ -0,0 +1,51 @@
#!/usr/bin/env python3
import http.client as http
import json
# curl -sS https://api.coingecko.com/api/v3/coins/list
COINS = [
# [id, symbol]
["monero", "XMR"],
["bitcoin", "BTC"],
["ordinals", "ORDI"],
]
CURRENCY = "usd"
FORMAT = "{coin}=${price:.0f}"
def get_btc_fees() -> str:
url = "mempool.space"
path = "/api/v1/fees/mempool-blocks"
client = http.HTTPSConnection(url)
client.request("GET", path)
# https://mempool.space/docs/api/rest#get-mempool-blocks-fees
response = json.loads(client.getresponse().read())
return f"{int(response[0]['medianFee'])} sat/vB"
def get_coins_values() -> str:
ids = ",".join([coin[0] for coin in COINS])
url = "api.coingecko.com"
path = f"/api/v3/simple/price?ids={ids}&vs_currencies={CURRENCY}"
client = http.HTTPSConnection(url)
client.request("GET", path)
# https://www.coingecko.com/api/documentation
prices = json.loads(client.getresponse().read())
return " ".join(
FORMAT.format(coin=coin[1], price=prices[coin[0]][CURRENCY])
for coin in COINS
)
def main():
print(f"{get_btc_fees()} {get_coins_values()}")
if __name__ == "__main__":
main()

3
.local/bin/debian Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash -e
podman run --rm -it -v "$PWD:/mnt/" -w /mnt/ docker.io/debian:12-slim

27
.local/bin/epitest Executable file
View file

@ -0,0 +1,27 @@
#!/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 \
"$@"

49
.local/bin/light Executable file
View file

@ -0,0 +1,49 @@
#!/bin/bash -e
function round() {
local nb="$1"
local closest="${2#-}"
local mod; mod="$((nb % closest))"
if [ "$mod" -lt "$((closest / 2))" ]; then
echo "$((nb - mod))"
else
echo "$((nb + closest - mod))"
fi
}
function get_current() {
local d="$1"
local cur; cur="$(cat "$1/brightness")"
local max; max="$(cat "$1/max_brightness")"
echo "$((cur * 100 / max))"
}
function set_light() {
local d="$1"
local max; max="$(cat "$d/max_brightness")"
echo "$((CUR * max / 100))" > "$d/brightness"
}
NOTIFY='notify-send -t 1000 -a changeBrightness -u low'
NOTIFYVOL="$NOTIFY -i audio-volume-high"
DIRS=(/sys/class/backlight/*)
CUR="$(get_current "${DIRS[0]}")"
case "${1:0:1}" in
'') echo "$CUR"; exit ;;
'+'|'-') CUR="$(round $((CUR + "$1")) "$1")" ;;
*) CUR="$1" ;;
esac
[ "$CUR" -lt 0 ] && CUR=0
[ "$CUR" -gt 100 ] && CUR=100
for d in "${DIRS[@]}"; do
set_light "$d"
done
$NOTIFYVOL -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"

1
.local/bin/lock Executable file
View file

@ -0,0 +1 @@
#!/usr/bin/env -Si3lock -ftni "${XDG_CONFIG_HOME}/wallpapers/lock.png"

8
.local/bin/mouse_360 Executable file
View file

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

3
.local/bin/passinfo Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash -e
pass show "$(cat /tmp/passselect)" | less

4
.local/bin/passopen Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash -e
xdg-open \
"$(pass show "$(cat /tmp/passselect)" | sed -n '/^URL:/{s/URL:\s*//p;q}')"

3
.local/bin/passotp Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash -e
xdotool type --clearmodifiers --delay 0 "$(pass otp "$(cat /tmp/passselect)")"

4
.local/bin/passpass Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash -e
xdotool type --clearmodifiers --delay 0 \
"$(pass show "$(cat /tmp/passselect)" | head -n1 -)"

14
.local/bin/passselect Executable file
View file

@ -0,0 +1,14 @@
#!/bin/bash -e
shopt -s nullglob globstar
prefix="${PASSWORD_STORE_DIR-"$HOME"/.password-store}"
password_files=("$prefix"/**/*.gpg)
password_files=("${password_files[@]#"$prefix"/}")
password_files=("${password_files[@]%.gpg}")
password_file="$(printf '%s\n' "${password_files[@]}" | dmenu "$@")"
[ -n "$password_file" ] || exit
echo "$password_file" > /tmp/passselect

4
.local/bin/passuser Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash -e
xdotool type --clearmodifiers --delay 0 \
"$(pass show "$(cat /tmp/passselect)" | sed -n '/^Username:/{s/Username:\s*//p;q}')"

112
.local/bin/sbar Executable file
View file

@ -0,0 +1,112 @@
#!/bin/bash
function update_crypto() {
local c
c="$(crypto 2> /dev/null)" && crypto="$c"
}
function update_cpu() {
cpu=" $(awk '{print $1}' /proc/loadavg)"
}
function update_memory() {
memory=" $(free -h | awk '/^Mem:/{print $3}')"
}
function update_bat() {
local dir cap
dir='/sys/class/power_supply/BAT0'
cap="$(cat "$dir/capacity")"
{ grep -qv Discharging "$dir/status" && bat=" $cap%"; } ||
{ [ "$cap" -gt 80 ] && bat=" $cap%"; } ||
{ [ "$cap" -gt 60 ] && bat=" $cap%"; } ||
{ [ "$cap" -gt 40 ] && bat=" $cap%"; } ||
{ [ "$cap" -gt 20 ] && bat=" $cap%"; } ||
{ bat=" $cap%"; }
}
function update_sink_vol() {
local sink vol
sink="$(wpctl get-volume '@DEFAULT_AUDIO_SINK@')"
if grep -q MUTED <<< "$sink"; then
sink_vol='🔇'
return
fi
vol="$(awk '{print int($2 * 100)}' <<< "$sink")"
{ [ "$vol" -gt 67 ] && sink_vol=" $vol"; } ||
{ [ "$vol" -gt 33 ] && sink_vol=" $vol"; } ||
{ sink_vol=" $vol"; }
}
function update_source_vol() {
local source vol
source="$(wpctl get-volume '@DEFAULT_AUDIO_SOURCE@')"
if grep -q MUTED <<< "$source"; then
source_vol=''
return
fi
source_vol=" $(awk '{print int($2 * 100)}' <<< "$source")"
}
function update_wlp() {
local sig ssid dev=wlan0
sig="$(awk "/$dev/{print int(\$3)}" /proc/net/wireless)"
if [ -z "$sig" ]; then
wlp='⚠'
return
fi
ssid="$(networkctl status "$dev" | grep -Po 'Wi-Fi access point:\s*\K\w+')"
{ [ "$sig" -gt 56 ] && wlp="▂▄▆█ $ssid"; } ||
{ [ "$sig" -gt 38 ] && wlp="▂▄▆_ $ssid"; } ||
{ [ "$sig" -gt 21 ] && wlp="▂▄__ $ssid"; } ||
{ [ "$sig" -gt 3 ] && wlp="▂___ $ssid"; } ||
{ wlp="____ $ssid"; }
}
function update_time() {
time="$(date "+%a %m-%d %R")"
}
function display() {
"${DISPLAYCMD[@]}" "$crypto | $cpu | $memory | $sink_vol $source_vol | $wlp | $bat | $time"
}
if [ "$XDG_SESSION_TYPE" = wayland ]; then
DISPLAYCMD=(echo)
else
DISPLAYCMD=(xsetroot -name)
fi
# SIGNALING
# trap '<function>;display;wait' 'RTMIN+n'
trap 'update_sink_vol;display;wait' 'RTMIN'
trap 'update_wlp;display;wait' 'RTMIN+1'
# to update it from external commands
## kill -m "$(cat ~/.cache/pidofbar)"
# where m = 34 + n
echo "$$" > "$HOME/.cache/pidofbar"
sec=0
while true; do
wait && {
[ "$((sec % 300))" = 10 ] && update_crypto
[ "$((sec % 10))" = 0 ] && {
update_cpu
update_memory
update_sink_vol
update_source_vol
update_wlp
update_bat
update_time
display
}
sec="$((sec + 10))"
}
awk "@load \"time\"; BEGIN {d=10; s=$(date '+%S.%N'); sleep(d - s % d)}" &
done

1
.local/bin/steam Executable file
View file

@ -0,0 +1 @@
#!/usr/bin/env -Scom.valvesoftware.Steam -no-browser +open 'steam://open/minigameslist'

43
.local/bin/vol Executable file
View file

@ -0,0 +1,43 @@
#!/bin/bash -e
NOTIFY='notify-send -t 1000 -a changeVolume -u low'
NOTIFYVOL="$NOTIFY -i audio-volume-high"
SINK='@DEFAULT_AUDIO_SINK@'
WPCUR="$(wpctl get-volume "$SINK")"
CUR="$((10#$(tr -dc '0-9' <<< "$WPCUR")))"
grep -q MUTED <<< "$WPCUR" && MUTE=1 || MUTE=0
if [ "$1" == 'm' ]; then
if [ "$MUTE" = 1 ]; then
wpctl set-mute "$SINK" 0
$NOTIFYVOL -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"
else
wpctl set-mute "$SINK" 1
$NOTIFY -i audio-volume-muted -h string:synchronous:vol "Mute"
fi
else
case "${1:0:1}" in
'')
echo "$CUR"; exit
;;
'+'|'-')
CUR="$((CUR - CUR % $1 + $1))"
[ "$CUR" -lt 0 ] && CUR=0
[ "$CUR" -gt 150 ] && CUR=150
;;
*)
CUR="$1"
;;
esac
wpctl set-volume "$SINK" "$CUR%"
if [ "$MUTE" = 1 ]; then
wpctl set-mute "$SINK" 0
fi
$NOTIFYVOL -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"
fi
# update sbar
kill -34 "$(cat "$HOME/.cache/pidofbar")"

13
.local/bin/wlp Executable file
View file

@ -0,0 +1,13 @@
#!/bin/bash -e
iwctl=(iwctl station wlan0)
"${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 -35 "$(cat "$HOME/.cache/pidofbar")"
exit 0
fi
sleep 1
done