revamp run sh
This commit is contained in:
		
							
								
								
									
										19
									
								
								arch-user/bin/bemenu/run-calc.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										19
									
								
								arch-user/bin/bemenu/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 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 | ||||
							
								
								
									
										21
									
								
								arch-user/bin/bemenu/run-capture.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										21
									
								
								arch-user/bin/bemenu/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/bemenu/run-man.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										12
									
								
								arch-user/bin/bemenu/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 footclient --app-id="footclient_float" "$SHELL" -c "man '$page' || read -n1" | ||||
							
								
								
									
										15
									
								
								arch-user/bin/bemenu/run-pass.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										15
									
								
								arch-user/bin/bemenu/run-pass.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -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 | ||||
|  | ||||
							
								
								
									
										10
									
								
								arch-user/bin/bemenu/run-power.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										10
									
								
								arch-user/bin/bemenu/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 | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user