workspace/arch-user/bin/run.sh
2025-03-30 00:04:54 +00:00

212 lines
4.3 KiB
Bash
Executable File

#!/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