fixed issue that prevented the script from reading input from command line.
[bash-notes.git] / SOURCE / main.sh
1 # shellcheck disable=SC2006
2 GOPT=$(getopt -o hvplr:a:e:d:s: --long help,version,list,plain,userconf,showconf,sync,restore:,backup:,add:,edit:,delete:,show: -n 'bash-notes' -- "$@")
3
4 # shellcheck disable=SC2181
5 if [ $? != 0 ] ; then helptext >&2 ; exit 1 ; fi
6
7 # Note the quotes around `$GOPT': they are essential!
8 eval set -- "$GOPT"
9 unset GOPT
10
11 while true; do
12 case "$1" in
13 -h | --help )
14 helptext
15 exit
16 ;;
17 -v | --version )
18 echo $BASENAME v${VERSION}
19 exit
20 ;;
21 -p | --plain )
22 PLAIN=true
23 shift
24 ;;
25 -l | --list )
26 listnotes
27 exit
28 ;;
29 -a | --add )
30 TITLE=$2
31 shift 2
32 addnote "$TITLE"
33 exit
34 ;;
35 -e | --edit )
36 NOTE=$2
37 shift 2
38 editnote "$NOTE"
39 exit
40 ;;
41 -d | --delete )
42 NOTE=$2
43 shift 2
44 rmnote "$NOTE"
45 exit
46 ;;
47 -s | --show )
48 NOTE=$2
49 shift 2
50 shownote "$NOTE"
51 exit
52 ;;
53 -r | --restore )
54 RDIR=$2
55 shift 2
56 backup_restore $RDIR
57 exit
58 ;;
59 --sync )
60 # I'm forcing it because if you run it manually, chances are that you need to.
61 gitsync -f
62 shift
63 exit
64 ;;
65 --userconf )
66 export_config
67 # shellcheck disable=SC2317
68 echo "config exported to \"$RCFILE\""
69 # shellcheck disable=SC2317
70 exit
71 ;;
72 --showconf )
73 configtext
74 exit
75 ;;
76 --backup )
77 BDIR=$2
78 shift 2
79 backup_data $BDIR
80 exit
81 ;;
82 -- )
83 shift
84 break
85 ;;
86 * )
87 break
88 ;;
89 esac
90 done
91
92 for arg; do
93 if [ $(check_noteID $arg) ]; then
94 shownote $arg
95 else
96 helptext
97 exit
98 fi
99 done