feat: bookmarks

This commit is contained in:
ange 2025-02-17 06:08:25 +00:00
parent ddd00d7844
commit 98ec0130fd
Signed by: ange
GPG key ID: 9E0C4157BB7BEB1D
19 changed files with 223 additions and 90 deletions

View file

@ -1,34 +1,15 @@
#!/bin/bash -e
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
}
while true; do
mapfile -t LSBLK <<< "$(lsblk -n --paths --list | grep part)"
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

27
.local/bin/bookmarks Executable file
View file

@ -0,0 +1,27 @@
#!/bin/bash -e
shopt -s extglob
if [ "$1" = -p ]; then
BROWSER="$BROWSER --private-window"
elif [[ "$(xdotool getwindowfocus getwindowname)" != *'Mozilla Firefox' ]]; then
BROWSER="$BROWSER --new-window"
fi
mapfile -t list < <(grep -Pv '^(#|$)' "$XDG_CONFIG_HOME/bookmarks")
q="$(printf '%s\n' '' "${list[@]}" | dmenu -l 16)"
if [ -z "$q" ]; then
exec $BROWSER
elif [[ "$q" == *://* ]]; then
url="${q/*+( )/}"
if [ "$1" = -p ] || [[ "$url" == http?(s)://* ]]; then
exec $BROWSER "$url"
fi
exec xdg-open "$url"
fi
if [[ "$q" == *.* ]] && [[ "$q" != *' '* ]]; then
exec $BROWSER "$q"
fi
exec $BROWSER "https://searx.gmoker.com/search?q=$(jq -Rr '@uri' <<< "$q")"

View file

@ -1,9 +1,18 @@
#!/bin/bash -e
#!/bin/bash
declare -A aliases
aliases=(
function dkr() {
local ep="$1"; shift
(set -x
podman run --rm -it -v "$PWD:/mnt/" -w /mnt/ --entrypoint "$ep" \
"$img" "$@"
)
}
declare -A aliases=(
[arch]=docker.io/archlinux/archlinux:base
[debian]=docker.io/debian:12-slim
[flutter]=git.gmoker.com/icing/flutter:main
[kaniko]=gcr.io/kaniko-project/executor:debug
)
@ -19,5 +28,7 @@ else
fi
shift
set -x
podman run --rm -it -v "$PWD:/mnt/" -w /mnt/ "$img" "$@"
dkr bash "$@"
if [ "$?" = 127 ]; then
dkr sh "$@"
fi

View file

@ -1,14 +1,14 @@
#!/bin/bash -e
STEPS=16
DIR="$(printf '%s\n' /sys/class/backlight/* | head -n1)"
DIR="$(find /sys/class/backlight/* -print -quit)"
CUR="$(cat "$DIR/brightness")"
MAX=$(cat "$DIR/max_brightness")
case "${1:0:1}" in
'') echo "$CUR"; exit ;;
'+'|'-') CUR="$(((CUR / STEPS + $1) * STEPS))" ;;
'+'|'-') CUR=$(((CUR / STEPS + $1) * STEPS)) ;;
*) CUR="$1" ;;
esac

View file

@ -32,8 +32,8 @@ function update_bat() {
function update_sink_vol() {
local vol mute
read -r vol mute < <(wpctl get-volume '@DEFAULT_AUDIO_SINK@')
vol="$((10#${vol/./}))"
read -r _ vol mute < <(wpctl get-volume '@DEFAULT_AUDIO_SINK@') || return
vol=$((10#${vol/./}))
if [ -n "$mute" ]; then sink_vol='🔇'
elif [ "$vol" -gt 67 ]; then sink_vol=" $vol"
elif [ "$vol" -gt 33 ]; then sink_vol=" $vol"
@ -44,8 +44,8 @@ function update_sink_vol() {
function update_source_vol() {
local vol mute
read -r vol mute < <(wpctl get-volume '@DEFAULT_AUDIO_SOURCE@')
vol="$((10#${vol/./}))"
read -r _ vol mute < <(wpctl get-volume '@DEFAULT_AUDIO_SOURCE@') || return
vol=$((10#${vol/./}))
if [ -n "$mute" ]; then source_vol='🔇'
else source_vol=" $vol"
fi
@ -76,6 +76,14 @@ function update_net() {
esac
}
function update_vpn() {
local v; v="$(ip -br link show type wireguard | awk '{print $1}')"
if [ -n "$v" ]; then vpn=" 🔒 $v"
else vpn=
fi
}
function update_time() {
time="$(TZ=Asia/Makassar date '+%R %Z') - $(date -u '+%a %m-%d %R')"
}
@ -85,7 +93,7 @@ function reload() {
}
function display() {
"${DISPLAYCMD[@]}" "$crypto | $cpu | $memory | $sink_vol $source_vol | $net | $bat | $time"
"${DISPLAYCMD[@]}" "$crypto | $cpu | $memory | $sink_vol $source_vol | $net$vpn | $bat | $time"
}
if [ "$XDG_SESSION_TYPE" = wayland ]; then
@ -100,26 +108,29 @@ 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'
trap 'update_vpn;display;wait' 'RTMIN+4'
# to update it from external commands
## kill -m "$(cat ~/.cache/pidofbar)"
## kill -m "$(cat "$XDG_CACHE_HOME/pidofbar")"
# where m = 34 + n
echo "$$" > "$HOME/.cache/pidofbar"
echo "$$" > "$XDG_CACHE_HOME/pidofbar"
sec=0
while true; do
[ "$((sec % 300))" -eq 5 ] && update_crypto
[ "$((sec % 5))" -eq 0 ] && {
if [ $((sec % 300)) -eq 5 ]; then
update_crypto
fi
if [ $((sec % 5)) -eq 0 ]; then
update_cpu
update_memory
update_sink_vol
update_source_vol
update_net
update_vpn
update_bat
update_time
display
}
fi
((sec += 5))
awk "@load \"time\"; BEGIN {d=5; s=$(date '+%S.%N'); sleep(d - s % d)}" &
wait
sleep $((5 - 10#$(date '+%S') % 5)) & wait
done

View file

@ -18,7 +18,8 @@ shift
function update_vol() {
case "$1" in
+*|-*)
CUR="$(($CUR + $1 - $CUR % $1 + $CUR % $1 * 10 / $1 / 5 * $1))"
# shellcheck disable=SC2017
CUR=$((CUR + $1 - CUR % $1 + CUR % $1 * 10 / $1 / 5 * $1))
if [ "$CUR" -lt 0 ]; then
CUR=0
elif [ "$CUR" -gt 300 ]; then
@ -32,7 +33,7 @@ function update_vol() {
}
read -r _ CUR MUTE < <(wpctl get-volume "$DEV")
CUR="$(("10#${CUR/./}"))"
CUR=$(("10#${CUR/./}"))
if [ -z "$1" ]; then
echo "$CUR"
@ -48,4 +49,4 @@ else
fi
fi
kill "-$SIG" "$(cat "$HOME/.cache/pidofbar")"
kill "-$SIG" "$(cat "$XDG_CACHE_HOME/pidofbar")"

View file

@ -10,7 +10,7 @@ fi
if [ "$EUID" != 0 ]; then
exec "$SUDO" env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" \
"$BASH" -- "${BASH_SOURCE[0]}" "$@"
XDG_CACHE_HOME="$XDG_CACHE_HOME" "$BASH" -- "${BASH_SOURCE[0]}" "$@"
fi
if [ -z "$1" ]; then
@ -24,3 +24,5 @@ done < <(wg show interfaces)
if [ "$1" != off ]; then
wg-quick up "$1"
fi
kill -38 "$(cat "$XDG_CACHE_HOME/pidofbar")"

View file

@ -1,6 +1,6 @@
#!/bin/bash -e
iwctl=(iwctl station "$(basename /sys/class/net/wlan*)")
iwctl=(iwctl station "$(find /sys/class/net/wlan* -print -quit)")
rfkill unblock wlan
if ! "${iwctl[@]}" show | grep -q 'Scanning\s\+yes'; then
@ -9,7 +9,7 @@ fi
for _ in {0..29}; do
if "${iwctl[@]}" show | grep -q '\s*State\s\+connected\s*$'; then
kill -37 "$(cat "$HOME/.cache/pidofbar")"
kill -37 "$(cat "$XDG_CACHE_HOME/pidofbar")"
exit 0
fi
sleep 1