removed redundant query for notes details if not added from command line input.
[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 shift 2
31 addnote "$TITLE"
32 exit
33 ;;
34 -e | --edit )
35 shift 2
36 editnote "$NOTE"
37 exit
38 ;;
39 -d | --delete )
40 shift 2
41 rmnote "$NOTE"
42 exit
43 ;;
44 -s | --show )
45 shift 2
46 shownote "$NOTE"
47 exit
48 ;;
49 -r | --restore )
50 shift 2
51 backup_restore $RDIR
52 exit
53 ;;
54 --sync )
55 # I'm forcing it because if you run it manually, chances are that you need to.
56 gitsync -f
57 shift
58 exit
59 ;;
60 --userconf )
61 export_config
62 # shellcheck disable=SC2317
63 echo "config exported to \"$RCFILE\""
64 # shellcheck disable=SC2317
65 exit
66 ;;
67 --showconf )
68 configtext
69 exit
70 ;;
71 --backup )
72 shift 2
73 backup_data $BDIR
74 exit
75 ;;
76 -- )
77 shift
78 break
79 ;;
80 * )
81 break
82 ;;
83 esac
84 done
85
86 for arg; do
87 if [ $(check_noteID $arg) ]; then
88 shownote $arg
89 else
90 helptext
91 exit
92 fi
93 done