bemenu -> wmenu
This commit is contained in:
2
arch-user/bin/menu/horizontal.sh
Executable file
2
arch-user/bin/menu/horizontal.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
eval "wmenu $WMENU_HOPTS \"$@\""
|
||||
252
arch-user/bin/menu/pinentry.sh
Executable file
252
arch-user/bin/menu/pinentry.sh
Executable file
@@ -0,0 +1,252 @@
|
||||
#!/bin/bash -efu
|
||||
# based on https://github.com/legionus/pinentry-bash/blob/master/pinentry-bash
|
||||
|
||||
### 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
|
||||
|
||||
############################### PATCH #################################
|
||||
. ~/.config/menu/env.sh
|
||||
#######################################################################
|
||||
|
||||
VERSION='1.0'
|
||||
FLAVOR='bash'
|
||||
|
||||
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 #################################
|
||||
~/.local/bin/menu/horizontal.sh \
|
||||
-Pp "${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
|
||||
19
arch-user/bin/menu/run-calc.sh
Executable file
19
arch-user/bin/menu/run-calc.sh
Executable file
@@ -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 alacritty msg create-window --class="term_float" --working-directory="$HOME" --command "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
|
||||
21
arch-user/bin/menu/run-capture.sh
Executable file
21
arch-user/bin/menu/run-capture.sh
Executable file
@@ -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
|
||||
12
arch-user/bin/menu/run-man.sh
Executable file
12
arch-user/bin/menu/run-man.sh
Executable file
@@ -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 alacritty msg create-window --class="term_float" --working-directory="$HOME" --command "man '$page' || read -n1"
|
||||
13
arch-user/bin/menu/run-pass.sh
Executable file
13
arch-user/bin/menu/run-pass.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
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 "$2" in
|
||||
info) exec alacritty msg create-window --class="term_float" --working-directory="$HOME" --command "pass $pw | vim -";;
|
||||
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
|
||||
|
||||
10
arch-user/bin/menu/run-power.sh
Executable file
10
arch-user/bin/menu/run-power.sh
Executable file
@@ -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
|
||||
22
arch-user/bin/menu/run.sh
Executable file
22
arch-user/bin/menu/run.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
rl_full="$(cat ~/.config/menu/*.runlist)"
|
||||
rl="$(echo "$rl_full" | cut -d' ' -f2-)"
|
||||
|
||||
inp="$(echo "$rl" | ~/.local/bin/menu/vertical.sh -p ">")"
|
||||
[ -z "$inp" ] && exit 0
|
||||
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"
|
||||
|
||||
case "$exectr" in
|
||||
exec) exec $inp;;
|
||||
float-sh) exec alacritty msg create-window --class="term_float" --working-directory="$HOME" --command "$SHELL" -c "($inp)";;
|
||||
float-sh-keep) exec alacritty msg create-window --class="term_float" --working-directory="$HOME" --command "($inp); read -n1";;
|
||||
*) exec bash "$HOME/.local/bin/menu/run-$exectr.sh" "${inp_arr[@]}"
|
||||
esac
|
||||
4
arch-user/bin/menu/vertical.sh
Executable file
4
arch-user/bin/menu/vertical.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
input=$(cat)
|
||||
lines=$(echo "$input" | wc -l)
|
||||
echo "$input" | eval "wmenu $WMENU_VOPTS -l $((lines < 50 ? lines : 50)) \"$@\""
|
||||
Reference in New Issue
Block a user