-
Notifications
You must be signed in to change notification settings - Fork 0
/
akory
executable file
·64 lines (50 loc) · 1.17 KB
/
akory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
mena='\e[0;31m'
tsotra='\e[0;m'
maintso='\e[0;32m'
# fonction affichant un output d'aide au cas de mauvaise utilisation de la commande
function usage {
echo -e "Usage: ${maintso} $0 ${tsotra} [-d <delay>] text \n" 1>&2;
echo -e "-d: write delay for each character. default 0.1" 1>&2;
exit $1;
}
function typewriter
{
text="$1"
delay="$2"
for i in $(seq 0 $(expr length "${text}")) ; do
echo -en "${text:$i:1}"
sleep ${delay}
done
echo
}
# Analyse des parametres entrée avec la commande
while getopts "d:" option; do
case "${option}" in
d)
delay=${OPTARG}
regex_number='^[0-9.]+$'
if ! [[ $delay =~ $regex_number ]] ; then
echo "${mena}Not a number $delay ${tsotra}"
usage 1
fi
;;
*)
usage 1
;;
esac
done
shift $((OPTIND-1))
if test ! -t 0; then
text=`cat < /dev/stdin`
elif [ $# -le 0 ] ; then
echo -e "${mena}Missing text \n${tsotra}";
usage 1
else
text=$@
fi
if [ ! -z "${delay}" ] ; then
typewriter "$text" $delay
else
typewriter "$text" .1
fi