From 14263c00b23a18e3a54c5478d5752780fde773ca Mon Sep 17 00:00:00 2001 From: Yuri Zamyatin Date: Sat, 5 Jul 2025 23:11:30 +0000 Subject: [PATCH] revamp run sh --- arch-platform/README.md | 5 +- arch-user/bin/bemenu/run-calc.sh | 19 +++ arch-user/bin/bemenu/run-capture.sh | 21 +++ arch-user/bin/bemenu/run-man.sh | 12 ++ arch-user/bin/bemenu/run-pass.sh | 15 ++ arch-user/bin/bemenu/run-power.sh | 10 ++ arch-user/bin/bemenu/run.sh | 223 ++------------------------- arch-user/config/bemenu/base.runlist | 18 +++ arch-user/config/mako/config.tmpl | 4 + 9 files changed, 116 insertions(+), 211 deletions(-) create mode 100755 arch-user/bin/bemenu/run-calc.sh create mode 100755 arch-user/bin/bemenu/run-capture.sh create mode 100755 arch-user/bin/bemenu/run-man.sh create mode 100755 arch-user/bin/bemenu/run-pass.sh create mode 100755 arch-user/bin/bemenu/run-power.sh create mode 100644 arch-user/config/bemenu/base.runlist diff --git a/arch-platform/README.md b/arch-platform/README.md index 6da7646..b6fa3af 100644 --- a/arch-platform/README.md +++ b/arch-platform/README.md @@ -112,7 +112,4 @@ passwd 23. login, `sudo su` 24. Uncomment locale in `/etc/locale.gen`, run `locale-gen` 25. `echo "" > /etc/hostname` -26. `systemctl enable NetworkManager --now` -27. Enable and sync time: `systemctl enable systemd-timesyncd --now` -28. Get tz from `tzselect`, set via `timedatectl set-timezone [tz]` -29. Update hwclock: `hwclock -w --utc` +26. Get tz from `tzselect`, set via `timedatectl set-timezone [tz]` diff --git a/arch-user/bin/bemenu/run-calc.sh b/arch-user/bin/bemenu/run-calc.sh new file mode 100755 index 0000000..d15741c --- /dev/null +++ b/arch-user/bin/bemenu/run-calc.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +shift +query="$1" +if [ -z "$query" ]; then + query="$(echo "tui" | bemenu --prompt "qalc")" +fi +if [ "$query" = "tui" ]; then + exec footclient --app-id="footclient_float" -D ~/ "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" + elif [ -n "$menu_res" ]; then + "$0" _ "$menu_res" + fi +fi diff --git a/arch-user/bin/bemenu/run-capture.sh b/arch-user/bin/bemenu/run-capture.sh new file mode 100755 index 0000000..183c2c2 --- /dev/null +++ b/arch-user/bin/bemenu/run-capture.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +if [ "$*" = "screenshot output" ]; then + mon="$(swaymsg -t get_outputs | jq -r '. | map(select(.focused == true)) | .[0].name')" + outfile="screenshot-$(date +%s).png" + grim -o "$mon" - | tee ~/tmp/"$outfile" | wl-copy -t image/png + notify-send Done -a screenshot "Saved to tmp/$outfile\nCopied to clipboard" +elif [ "$*" = "screenshot selection" ]; then + outfile="screenshot-$(date +%s).png" + grim -g "$(slurp)" - | tee ~/tmp/"$outfile" | wl-copy -t image/png + notify-send Done -a screenshot "Saved to tmp/$outfile\nCopied to clipboard" +elif [ "$*" = "pick-color" ]; then + hex="$( + grim -g "$(slurp -p)" -t ppm - | \ + magick - -format '%[pixel:p{0,0}]' txt:- | \ + tail -n 1 | \ + cut -d ' ' -f 4 + )" + echo -n "$hex" | wl-copy + notify-send "$hex" -a screenshot "Color code copied to clipboard" +fi diff --git a/arch-user/bin/bemenu/run-man.sh b/arch-user/bin/bemenu/run-man.sh new file mode 100755 index 0000000..dc26cbc --- /dev/null +++ b/arch-user/bin/bemenu/run-man.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +shift +page="$1" +if [ -z "$page" ]; then + page="$( + man -k . | \ + (bemenu --prompt "man" || exec ~/.local/bin/bemenu/run.sh) | \ + sed ' s/\s\+\-.*//;s/ //g' + )" +fi +exec footclient --app-id="footclient_float" "$SHELL" -c "man '$page' || read -n1" diff --git a/arch-user/bin/bemenu/run-pass.sh b/arch-user/bin/bemenu/run-pass.sh new file mode 100755 index 0000000..a4bb55e --- /dev/null +++ b/arch-user/bin/bemenu/run-pass.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +type="$1" +shift + +cd "$PASSWORD_STORE_DIR" +pws="$(find -path "*/.*" -prune -o -path "*/cred/*" -name "*.gpg" -printf '%P\n' | sed 's/\.gpg$//')" +pw="$(echo "$pws" | bemenu --prompt "pass")" + +case "$type" in + otp) pass otp -c "$pw" && notify-send "$pw" -a pass "OTP copied to clipboard, clears in 45s";; + *) pass -c "$pw" && notify-send "$pw" -a pass "Password copied to clipboard, clears in 45s";; +esac + diff --git a/arch-user/bin/bemenu/run-power.sh b/arch-user/bin/bemenu/run-power.sh new file mode 100755 index 0000000..4e65eb7 --- /dev/null +++ b/arch-user/bin/bemenu/run-power.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +sure() { + echo yes | bemenu --prompt "sure?" || exec ~/.local/bin/bemenu/run.sh +} + +case "$1" in + poweroff|reboot|suspend) sure && systemctl "$@";; + logout) sure && swaymsg exit;; +esac diff --git a/arch-user/bin/bemenu/run.sh b/arch-user/bin/bemenu/run.sh index b4873ff..458d7d2 100755 --- a/arch-user/bin/bemenu/run.sh +++ b/arch-user/bin/bemenu/run.sh @@ -1,211 +1,20 @@ #!/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" -) +rl_full="$(cat "$HOME/.config/bemenu/"*.runlist)" +rl="$(echo "$rl_full" | cut -d' ' -f2-)" -sure() { - echo yes | bemenu --prompt "sure?" -} +inp="$(echo "$rl" | bemenu --prompt ">")" +eval "inp_arr=($inp)" +exectr=float-sh-keep +while IFS= read -r line; do + if [[ "$inp" == "$line"* ]]; then + exectr="$(echo "$rl_full" | grep -F "$line" -m 1 | cut -d' ' -f1)" + fi +done <<< "$rl" -# 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 +case "$exectr" in + exec) exec $inp;; + float-sh) exec footclient --app-id="footclient_float" -D ~/ "$SHELL" -c "($inp)";; + float-sh-keep) exec footclient --app-id="footclient_float" -D ~/ "$SHELL" -c "($inp); read -n1";; + *) exec bash "$HOME/.local/bin/bemenu/run-$exectr.sh" "${inp_arr[@]}";; +esac diff --git a/arch-user/config/bemenu/base.runlist b/arch-user/config/bemenu/base.runlist new file mode 100644 index 0000000..d0030a7 --- /dev/null +++ b/arch-user/config/bemenu/base.runlist @@ -0,0 +1,18 @@ +exec qutebrowser +exec gimp +exec sqlitebrowser +exec telegram-desktop +man man +calc calc +power suspend +power poweroff +power poweroff --check-inhibitors=no +power logout +power reboot +pass pass +pass pass otp +pass pass info +capture screenshot selection +capture screenshot output +capture pick-color +float-sh nmtui diff --git a/arch-user/config/mako/config.tmpl b/arch-user/config/mako/config.tmpl index 7a5912c..f32ade4 100644 --- a/arch-user/config/mako/config.tmpl +++ b/arch-user/config/mako/config.tmpl @@ -9,3 +9,7 @@ padding=5,10 width=600 progress-color=#{{ .theme.color.fg_accent }}{{ math.Mul .theme.opacity.med 255 | conv.ToInt64 | printf "%02X" }} layer=overlay + +[app-name=screenshot] +default-timeout=10000 +