Enviado em 11/01/2024 - 16:00h
Este é um esboço de um menu checklist sem dialog ou similares.#!/bin/sh
: '
Two read functions for Bourne Shell (ueliton@disroot.org 28/07/23)
usage;
mini_read -t 3 -n 3 myVar
-n nchars return after reading NCHARS characters rather than waiting for a newline.
Just work with -s arg.
-t time out and return failure if a complete line of input is not read within TIMEOUT seconds.
-s do not echo input coming from a terminal
'
mini_read () {
#enquanto total args maior que 0
while [ $# -gt 0 ]; do
# caso primeiro arg
case "$1" in
-t)
MRTIME=$2 shift 2
;;
-n)
MRCOUNT=$2 shift 2
;;
-s)
MRSUPRE=$1 shift
;;
*)
if [ $# -eq 1 ]; then
MRVAR_NAME=$1
shift
else
echo "Invalid parameter: $1"
exit 1
fi
;;
esac
done
MRLAST_ARG=${!#}
eval "MRVAR=\$$MRLAST_ARG"
eval "${MRVAR_NAME}=\$MRVAR"
if [ -z "$MRTIME" ]; then
MRTIME=300
elif [ -z "$MRCOUNT" ]; then
MRCOUNT=300
fi
mrback_ground () {
(
sleep 1s
for MRLOOP in $(seq $MRTIME -1 0); do
MRPIDF=$(ps ax -o pid=,args=|grep "dd bs=1 count=$MRCOUNT"|grep -v 'grep'|head -n 1|grep -o -E '([0-9]{2,6})')
if [ -z "$MRPIDF" ]; then
MRLOOP=0
elif [ "$MRLOOP" -eq 0 ]; then
kill -s PIPE $MRPIDF >/dev/null 2>&1
kill -15 $MRPIDF >/dev/null 2>&1
fi
sleep 1s
done
)
}
mrback_ground </dev/null &>/dev/null &
MRFPID=$(echo "$!"|grep -o -E '([0-9]{2,6})')
unset MRINPUT_READ
if [ ! -z "$MRSUPRE" ]; then
stty -echo
fi
stty raw
MRINPUT_READ=$(dd bs=1 count="$MRCOUNT" 2>/dev/null)
stty -raw
stty echo
eval ${MRVAR_NAME}=$MRINPUT_READ
MRRPID=$(ps ax -o pid=|grep -o "$MRFPID")
if [ -z "$MRINPUT_READ" ] && [ ! -z "$MRRPID" ]; then
kill -s PIPE $MRFPID >/dev/null 2>&1
kill -15 $MRFPID >/dev/null 2>&1
printf "\n"
exit 1
else
printf "\n"
fi
}
#mini_read -n 2 -t 30 test
check_list(){
options(){
case $key in
A|a|1) case $Acheck in
A|a|1) Acheck="";;
*) Acheck="A";;
esac;;
B|b|2) case $Bcheck in
B|b|2) Bcheck="";;
*) Bcheck="B";;
esac;;
C|c|3) case $Ccheck in
C|c|3) Ccheck="";;
*) Ccheck="C";;
esac;;
D|d|4) case $Dcheck in
D|d|4) Dcheck="";;
*) Dcheck="D";;
esac;;
E|e|5) case $Echeck in
E|e|5) Echeck="";;
*) Echeck="E";;
esac;;
x|X) key="fim";;
esac
}
options
}
menu_list(){
a_check(){
if [ -z $Acheck ];then echo "( )";else echo "(x)";fi
}
b_check(){
if [ -z $Bcheck ];then echo "( )";else echo "(x)";fi
}
c_check(){
if [ -z $Ccheck ];then echo "( )";else echo "(x)";fi
}
d_check(){
if [ -z $Dcheck ];then echo "( )";else echo "(x)";fi
}
e_check(){
if [ -z $Echeck ];then echo "( )";else echo "(x)";fi
}
printf "\n Marque o que deseja digitando as letras referentes:
$(a_check) A. opt1
$(b_check) B. opt2
$(c_check) C. opt3
$(d_check) D. opt4
$(e_check) E. opt5
Digite X para sair\n"
}
until [ "$key" = fim ];do
clear
menu_list
mini_read -s -n 1 key
check_list
if [ "$key" = fim ]; then
break
fi
done
Como gerar qualquer emoji ou símbolo unicode a partir do seu teclado
Instalar e Configurar o Slackware Linux em 2025
Como configurar os repositórios do apt no Debian 12 em 2025
Passkeys: A Evolução da Autenticação Digital
Instalação de distro Linux em computadores, netbooks, etc, em rede com o Clonezilla
Configurando o Conky para iniciar corretamente no sistema
3 configurações básicas que podem melhorar muito a sua edição pelo editor nano
Como colorir os logs do terminal com ccze
Instalação Microsoft Edge no Linux Mint 22
Como configurar posicionamento e movimento de janelas no Lubuntu (Openbox) com atalhos de teclado
firefox nao guarda meus logins nos sites (1)
Instalar debian testing (13) "por cima" do debian 12 (2)
Erro de segmentação «Segmentation fault (core dumped)» ao retornar obj... (1)