This commit is contained in:
2025-05-02 22:22:10 +00:00
commit 51c616f9f0
52 changed files with 2934 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
#!/bin/bash
set -e
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]; then
echo "bad args" >&2
exit 1
fi
DEST=$(realpath "$2")
cd "$1"
#shellcheck disable=SC2016
find . \
-type f \
-not -path '*/.*' \
-path "$3" | \
xargs -0 -d \\n -n 1 sh -c "mkdir -p $DEST/\$(dirname \"\$1\")" sh
#shellcheck disable=SC2016
find . \
-type f \
-not -path '*/.*' \
-path "$3" \
-printf "$(pwd)/%P\n$DEST/%P\n" | \
xargs -0 -d \\n -n 2 sh -c "$4" sh
#for rel in $(find . -type f -name *.gpg); do
# DESTFILE=$(echo $DEST/$rel | sed 's/\.[^.]*$//')
# [ -f "$DESTFILE" ] && continue
# mkdir -p "$(dirname "$DESTFILE")"
# gpg --output "$DESTFILE" --decrypt "$rel"
#done

9
arch-user/bin/archiso/make.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
set -e
sudo rm -rf /tmp/archiso-work /tmp/archiso-out
cd ~/know/archiso
sudo mkarchiso -v -w /tmp/archiso-work -o /tmp/archiso-out "profile-$1"
iso=(/tmp/archiso-out/*)
sudo dd if="$iso" of="$2" status=progress bs=4M
sudo rm -rf /tmp/archiso-work /tmp/archiso-out

251
arch-user/bin/bemenu/pinentry.sh Executable file
View File

@@ -0,0 +1,251 @@
#!/bin/bash -efu
### This file is covered by the GNU General Public License,
### which should be included with libshell as the file LICENSE.
### All copyright information are listed in the COPYING.
#exec 2>/tmp/pinentry.log
#set -x
VERSION='1.0'
FLAVOR='bash'
############################### PATCH #################################
. ~/.config/bemenu/env.sh
#######################################################################
keyinfo=''
error=''
timeout=0
touch_file=''
readonly def_desc='Enter password for GPG key'
readonly def_prompt='Password:'
readonly def_title='GPG Key Credentials'
readonly def_repeat='Confirm password for GPG key'
readonly def_labelok='OK'
readonly def_labelnotok='Do not do this'
readonly def_labelcancel='Cancel'
# from /usr/include/gpg-error.h
readonly GPG_ERR_NO_ERROR=0
readonly GPG_ERR_TIMEOUT=62
readonly GPG_ERR_CANCELED=99
readonly GPG_ERR_NOT_CONFIRMED=114
readonly GPG_ERR_ASS_PARAMETER=280
strerror()
{
case "$1" in
$GPG_ERR_NO_ERROR) echo "Success" ;;
$GPG_ERR_TIMEOUT) echo "Timeout" ;;
$GPG_ERR_CANCELED) echo "Operation cancelled" ;;
$GPG_ERR_NOT_CONFIRMED) echo "Not confirmed" ;;
$GPG_ERR_ASS_PARAMETER) echo "IPC parameter error" ;;
esac
}
assuan_result()
{
[ "$1" -gt 0 ] &&
echo -n "ERR $(( 5 << 24 | $1 )) " ||
echo -n "OK "
strerror "$1"
}
cmd_settimeout()
{
[ -n "${1##0*}" ] && [ -n "${1##*[!0-9]*}" ] && [ "$1" -gt 0 ] 2>/dev/null ||
return 0
timeout="$1"
assuan_result $GPG_ERR_NO_ERROR
}
cmd_setkeyinfo()
{
[ "$1" = "--clear" ] &&
keyinfo="" ||
keyinfo="$1"
assuan_result $GPG_ERR_NO_ERROR
}
set_text_variable()
{
printf -v "$1" "${2//%/\\x}"
eval "set_$1=1"
assuan_result $GPG_ERR_NO_ERROR
}
cmd_setoption()
{
case "$1" in
default-prompt=*) set_text_variable prompt "${1#*=}" ;;
default-ok=*) set_text_variable labelok "${1#*=}" ;;
default-cancel=*) set_text_variable labelcancel "${1#*=}" ;;
touch-file=*)
touch_file="${1#*=}"
assuan_result $GPG_ERR_NO_ERROR
;;
*)
assuan_result $GPG_ERR_NO_ERROR
;;
esac
}
cmd_getinfo()
{
case "$1" in
version)
echo "D $VERSION"
assuan_result $GPG_ERR_NO_ERROR
;;
pid)
echo "D $BASHPID"
assuan_result $GPG_ERR_NO_ERROR
;;
flavor)
echo "D $FLAVOR"
assuan_result $GPG_ERR_NO_ERROR
;;
ttyinfo)
echo "D - - - - $(id -u 2>/dev/null || echo 0)/$(id -g 2>/dev/null || echo 0) -"
assuan_result $GPG_ERR_NO_ERROR
;;
*)
assuan_result $GPG_ERR_ASS_PARAMETER
;;
esac
}
cmd_getpin()
{
local ret=0 result output password=1 repeatpassword=3
output="$(
echo -n "|"
############################### PATCH #################################
bemenu \
--password indicator \
--prompt "${prompt:-$def_prompt}" \
</dev/null | tr -d '\n'
ret=${PIPESTATUS[0]}
# yad \
# --splash \
# --no-markup \
# --title="${title:-$def_title}" \
# --form \
# --separator="\n" \
# --field="${desc:-$def_desc}:LBL" \
# --field="${prompt:-$def_prompt}:H" \
# ${set_repeat:+--field="${repeat:-$def_repeat}:LBL"} \
# ${set_repeat:+--field="${prompt-$def_prompt}:H"} \
# ${error:+--field="$error:LBL"} \
# --button="${labelok:-$def_labelok}:0" \
# --button="${labelcancel:-$def_labelcancel}:1" \
# --timeout="${timeout:-0}" \
# </dev/null || ret=$?
######################################################################
echo -n "|"
exit $ret
)" || ret=$?
set_error='' error=''
case "$ret" in
1) assuan_result $GPG_ERR_CANCELED; return 0; ;;
70) assuan_result $GPG_ERR_TIMEOUT; return 0; ;;
esac
output="${output#|}"
output="${output%|}"
############################### PATCH #################################
declare -A result
result[$password]="$output"
result[$repeatpassword]="$output"
# readarray -t result <<<"$output"
# output=''
#
#######################################################################
if [ -n "${set_repeat-}" ]; then
set_repeat='' repeat=''
if [ "${result[$password]}" != "${result[$repeatpassword]}" ]; then
cmd_confirm --one-button "${repeaterror:-Error: Passwords did not match.}"
assuan_result $GPG_ERR_NOT_CONFIRMED
return
fi
echo "S PIN_REPEATED"
fi
[ -z "$touch_file" ] ||
touch "$touch_file"
echo "D ${result[$password]}"
assuan_result $GPG_ERR_NO_ERROR
}
cmd_confirm()
{
local ret=0 showmsg='' showcfm=1
if [ "$1" = '--one-button' ]; then
shift
showmsg=1
showcfm=
fi
yad \
--splash \
--no-markup \
--title="${title:-$def_title}" \
--text="${1:-${desc:-$def_desc}}" \
${showmsg:+--button="${labelok:-$def_labelok}:0"} \
${showcfm:+${error:+--field="$error:LBL"}} \
--timeout="${timeout:-0}" \
< /dev/null ||
ret=$?
set_error='' error=''
case "$ret" in
0) assuan_result $GPG_ERR_NO_ERROR ;;
1) assuan_result $GPG_ERR_CANCELED ;;
70) assuan_result $GPG_ERR_TIMEOUT ;;
*) assuan_result $GPG_ERR_NOT_CONFIRMED ;;
esac
}
echo "OK Your orders please"
while :; do
read -r cmd args 2>/dev/null ||
continue
#echo >&2 "$cmd: $args"
case "$cmd" in
BYE)
echo "OK closing connection"
exit 0
;;
GETPIN) cmd_getpin ;;
CONFIRM) cmd_confirm "$args" ;;
MESSAGE) cmd_confirm --one-button ;;
GETINFO) cmd_getinfo "$args" ;;
SETTIMEOUT) cmd_settimeout "$args" ;;
SETKEYINFO) cmd_setkeyinfo "$args" ;;
OPTION) cmd_setoption "$args" ;;
SETDESC) set_text_variable desc "$args" ;;
SETPROMPT) set_text_variable prompt "$args" ;;
SETTITLE) set_text_variable title "$args" ;;
SETOK) set_text_variable labelok "$args" ;;
SETCANCEL) set_text_variable labelcancel "$args" ;;
SETNOTOK) set_text_variable labelnotok "$args" ;;
SETERROR) set_text_variable error "$args" ;;
SETREPEAT) set_text_variable repeat "$args" ;;
SETREPEATERROR) set_text_variable repeaterror "$args" ;;
*)
assuan_result $GPG_ERR_NO_ERROR
;;
esac
done

View File

@@ -0,0 +1,13 @@
#!/bin/bash
set -e
if [ -z "$PASSPHRASE" ]; then
read -srp "Password: " PASSPHRASE
echo
fi
export PASSPHRASE
bash ~/.local/bin/alg/file-tree-apply.sh "$1" "$2" '*.gpg' \
'if [ ! -f "$2" ]; then gpg --decrypt "$1" | gpg --symmetric --output "$2" --passphrase "$PASSPHRASE" --batch --yes; fi'
echo ok

View File

@@ -0,0 +1,14 @@
#!/bin/sh
read -r stat </sys/class/power_supply/ACAD/online
read -r cap </sys/class/power_supply/BAT1/capacity
read -r volt </sys/class/power_supply/BAT1/voltage_now
read -r curr </sys/class/power_supply/BAT1/current_now
w=$((volt*curr/1000000000000))
if [ "$stat" = "1" ]; then
echo "🔌 $cap% ${w}W"
else
echo "🔋 $cap% ${w}W"
[ "$cap" -lt "15" ] && exit 33
fi

View File

@@ -0,0 +1,23 @@
#!/bin/sh
sink_mute=$(pactl get-sink-mute @DEFAULT_SINK@)
case "$sink_mute" in
*yes*) sink_res=M;;
*) sink_res=$(pactl get-sink-volume @DEFAULT_SINK@ | sed -e 's/.*\s\([0-9]*\)%.*/\1/;t;d');;
esac
source_mute=$(pactl get-source-mute @DEFAULT_SOURCE@)
case "$source_mute" in
*yes*) source_res=M;;
*) source_res=$(pactl get-source-volume @DEFAULT_SOURCE@ | sed -e 's/.*\s\([0-9]*\)%.*/\1/;t;d');;
esac
bt_status="$(bluetoothctl devices Connected)"
if [ -n "$bt_status" ]; then
sink_icon=🎧
else
sink_icon=🔈
fi
echo "$sink_icon $sink_res% 🎙 $source_res%"

View File

@@ -0,0 +1,3 @@
#!/bin/bash
curl "https://wttr.in/?format=%l;%t%20%p" --silent | sed 's/^\(.\{3\}\)\(.*\);/\1 /'
echo

View File

@@ -0,0 +1,2 @@
#!/bin/sh
swaymsg -t get_inputs | jq -r 'map(select(has("xkb_active_layout_name")))[0].xkb_active_layout_name'

6
arch-user/bin/init Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/sh
. /etc/profile
. ~/.profile
sway --unsupported-gpu >>~/.local/state/sway/out.log 2>>~/.local/state/sway/err.log

View File

@@ -0,0 +1,12 @@
#!/bin/bash
for range in $(fc-match --format='%{charset}\n' "$1"); do
for n in $(seq "0x${range%-*}" "0x${range#*-}"); do
printf "%04x\n" "$n"
done
done | while read -r n_hex; do
count=$((count + 1))
printf "%-5s\U$n_hex\t" "$n_hex"
[ $((count % 10)) = 0 ] && printf "\n"
done
printf "\n"

View File

@@ -0,0 +1,2 @@
#!/bin/sh
pacman -Qdttq | sudo pacman -Rns -

211
arch-user/bin/run.sh Executable file
View File

@@ -0,0 +1,211 @@
#!/bin/bash
LIST=();
# gui
if [ "$USER" = "yrzam" ]; then
LIST+=(
"web" "web projects"
"web" "web life"
)
WEB_HAS_PROFILES=1
else
LIST+=(
"web" "web"
)
fi
LIST+=(
"gui" "telegram-desktop"
"gui" "gimp"
"gui" "sqlitebrowser"
# tui
"shell_tui" "vifm"
"shell_tui" "vim"
"tui" "htop"
"float_tui" "nmtui"
"float_tui" "bluetoothctl"
"man" "man"
"float_tui" "node"
"term" "term"
# native
"screen_pick" "screenshot output"
"screen_pick" "screenshot selection"
"screen_pick" "color-picker"
"todo" "pass"
"calc" "calc"
"todo" "translate ru-en"
"todo" "translate en-ru"
"grep_dict" "dict"
)
if [ "$FEAT_BRIGHTNESS" ]; then
LIST+=(
"brightness" "brightness"
)
fi
LIST+=(
"direct" "sway reload"
"power" "logout"
"todo" "inhibit"
"power" "suspend"
"power" "poweroff"
"power" "poweroff --check-inhibitors=no"
"power" "reboot"
)
sure() {
echo yes | bemenu --prompt "sure?"
}
# generic
exec_gui() {
exec "$@"
}
exec_tui() {
exec footclient -D ~/ "$@"
}
exec_float_tui() { # todo
exec footclient --app-id="footclient_float" -D ~/ "$@"
}
exec_shell_tui() {
exec footclient -D ~/ "$SHELL" -c "$@"
}
exec_shell_full() {
exec footclient -D ~/ "$SHELL" -c "($1); read -n1"
}
exec_direct() {
exec "$@"
}
exec_term() {
exec footclient -D ~/
}
# custom
exec_web() {
shift
if [ "$WEB_HAS_PROFILES" ]; then
shift
fi
qutebrowser "$*"
}
exec_man() {
shift
page="$1"
if [ -z "$page" ]; then
page="$(
man -k . | \
bemenu --prompt "man" | \
sed ' s/\s\+\-.*//;s/ //g'
)"
fi
[ -n "$page" ] && exec footclient "$SHELL" -c "man '$page' || read -n1"
}
exec_screen_pick() {
if [ "$*" = "screenshot output" ]; then
mon="$(swaymsg -t get_outputs | jq -r '. | map(select(.focused == true)) | .[0].name')"
grim -o "$mon" - | wl-copy -t image/png
notify-send Done -a screenshot "PNG image copied to clipboard" -t 3000
elif [ "$*" = "screenshot selection" ]; then
grim -g "$(slurp)" - | wl-copy -t image/png
notify-send Done -a screenshot "PNG image copied to clipboard" -t 3000
elif [ "$*" = "color-picker" ]; then
hex="$(
grim -g "$(slurp -p)" -t ppm - | \
magick - -format '%[pixel:p{0,0}]' txt:- | \
tail -n 1 | \
cut -d ' ' -f 4
)"
notify-send "$hex" -a screenshot "stnrit" -t 3000
fi
}
exec_pass() {
echo 1
}
exec_calc() {
shift
query="$1"
if [ -z "$query" ]; then
query="$(echo "tui" | bemenu --prompt "qalc")"
fi
if [ "$query" = "tui" ]; then
exec_float_tui "qalc"
elif [ -n "$query" ]; then
qalc_res="$(qalc --terse "$query")"
menu_res="$(echo -e "$qalc_res\ntui" | bemenu --prompt "qalc")"
if [ "$qalc_res" = "$menu_res" ]; then
wl-copy "$qalc_res"
notify-send "$qalc_res" -a calc "Result copied to clipboard" -t 3000
elif [ -n "$menu_res" ]; then
exec_calc _ "$menu_res"
fi
fi
}
exec_transl() {
echo 1
}
exec_grep_dict() {
shift
dict="$1"
pattern="$2"
dicts_path="$HOME/know/dict/"
if [ -z "$dict" ]; then
dict="$(find "$dicts_path" -type f -printf "%f\n" | bemenu --prompt "dict")"
[ -z "$dict" ] && return
fi
if [ -z "$pattern" ]; then
pattern="$(echo -n | bemenu --prompt "grep $dict")"
[ -z "$pattern" ] && return
fi
res="$({ echo ..; grep "$pattern" "$dicts_path/$dict"; } | bemenu --prompt " ")"
if [ "$res" = ".." ]; then
exec_grep_dict _ "$dict"
else
wl-copy "$res"
notify-send "$res" -a dict "Word copied to clipboard" -t 3000
fi
}
exec_brightness() {
shift
target="$1"
if [ -z "$target" ]; then
current="$(($(brightnessctl g)*100/$(brightnessctl m)))"
current_i="$((current/5))"
list="$(echo 1%; seq 5 5 100 | sed 's/$/%/')";
target="$(echo "$list" | bemenu --index $current_i --prompt "$current% ->")";
fi
if [ -n "$target" ] && [ "$target" != "$current%" ]; then
brightnessctl set "$target"
[ -z "$1" ] && exec_brightness _
fi
}
exec_power() {
case "$1" in
poweroff|reboot|suspend) sure && systemctl "$@";;
logout) sure && swaymsg exit;;
esac
}
if [ -n "$1" ]; then
out="$*";
else
out=$(
for (( i=1; i<${#LIST[@]}; i+=2 )); do
echo "${LIST[$i]}";
done | bemenu --prompt ">"
)
fi
if [ "$out" ]; then
for (( i=1; i<${#LIST[@]}; i+=2 )); do
if [[ "$out" == "${LIST[$i]}"* ]]; then
executor=${LIST[$((i-1))]}
fi
done
[ -z "$executor" ] && executor=shell_full
if [ "$executor" = "shell_full" ]; then
"exec_$executor" "$out"
else
eval "executor_args=($out)"
#shellcheck disable=SC2154
"exec_$executor" "${executor_args[@]}"
fi
fi

View File

@@ -0,0 +1,4 @@
#!/bin/sh
brig="$(brightnessctl set "$1" -m | sed -e 's/.*,\([0-9]*\)%.*/\1/')"
notify-send -t 2000 -h "int:value:$brig" -a "brightness" "$brig%" \
-h string:x-canonical-private-synchronous:brightness

View File

@@ -0,0 +1,6 @@
#!/bin/bash
out="$(printf '' | bemenu --prompt ':sway')"
eval "executor_args=($out)"
#shellcheck disable=SC2154
sway "${executor_args[@]}"