-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtel-hints
executable file
·49 lines (47 loc) · 1.13 KB
/
tel-hints
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
#!/usr/bin/env bash
# by @SealyJ - github.com/sealedjoy
version=0.2
hintsfile=~/.tel/help/hints
option="${1}"
[[ -e $hintsfile ]] || "Hints file missing, recommended to update" > ${hintsfile} #if no list make a new one
if [ -z "$1" ] ; then
n=0
hint_file_lines=()
IFS=$'\n'
while read line;
do
#add to array then select
n=$(( $n + 1 ))
hint_file_lines+=($line)
done < $hintsfile
#select random num from pool
randomiser=$((RANDOM % $n))
selected_hint=${hint_file_lines[$randomiser]} #get line at position
echo "${selected_hint}"
else
case ${option} in
-v | --version)
printf "\e[33;5;2m Hint\e[m: version: $version"
exit 0
;;
-h | --help)
echo "tel-hint [OPTION]
'$> tel-hint' = give me a hint
'$> tel-hint -h' = show this help menu
'$> tel-hint -v' = show version info
'$> tel-hint -a' = show all hints in list'
'$> tel-hint -e' = open hints list in $EDITOR'"
;;
-a | --all)
cat "$hintsfile"
;;
-e | --edit)
echo "Opening in $EDITOR"
$EDITOR $hintsfile
;;
*)
printf "\e[33;5;2m Hint:\e[munrecognised option"
exit 1
;;
esac
fi