From d9031203e22e4ef381c482b4594521323647487e Mon Sep 17 00:00:00 2001 From: nea Date: Thu, 13 Jan 2022 00:01:56 +0100 Subject: Initial commit --- choose | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 choose (limited to 'choose') diff --git a/choose b/choose new file mode 100755 index 0000000..6d750d3 --- /dev/null +++ b/choose @@ -0,0 +1,63 @@ +#!/bin/bash + +if [ "a$1" == "a--help" ] || [ "a$1" == "a-h" ]; then + cat <"$tty" +while true; do + printf "\e[u\e[s\e[K" >"$tty" + for ((i = 0; i < optionslength; i++)); do + if [ "$i" -eq $sel ]; then + printf "\e[30;47m" >"$tty" + fi + printf "%s\e[40;37m " "${options[$i]}" >"$tty" + done + case "$(./readkey <"$tty")" in + left) + sel=$((sel - 1)) + ;; + right) + sel=$((sel + 1)) + ;; + q) + printf "\e[u\e[KSelection aborted\n" >"$tty" + exit 1 + ;; + enter) + break + ;; + esac + if ((sel < 0)); then + sel=0 + fi + if ((sel >= optionslength)); then + sel=$((optionslength - 1)) + fi + +done +printf "\e[u\e[KSelected %s\n" "${options[$sel]}" >"$tty" + +if [ "$printidx" -eq 1 ]; then + echo "$sel" +else + echo "${options[$sel]}" +fi -- cgit