removed redundant query for notes details if not added from command line input.
[bash-notes.git] / SOURCE / main.sh
CommitLineData
fb711183 1# shellcheck disable=SC2006
da52e73a 2GOPT=$(getopt -o hvplr:a:e:d:s: --long help,version,list,plain,userconf,showconf,sync,restore:,backup:,add:,edit:,delete:,show: -n 'bash-notes' -- "$@")
fb711183 3
4# shellcheck disable=SC2181
5if [ $? != 0 ] ; then helptext >&2 ; exit 1 ; fi
6
7# Note the quotes around `$GOPT': they are essential!
8eval set -- "$GOPT"
9unset GOPT
10
11while 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 )
fb711183 30 shift 2
31 addnote "$TITLE"
07d42c7a 32 exit
fb711183 33 ;;
34 -e | --edit )
fb711183 35 shift 2
36 editnote "$NOTE"
07d42c7a 37 exit
fb711183 38 ;;
39 -d | --delete )
fb711183 40 shift 2
41 rmnote "$NOTE"
07d42c7a 42 exit
fb711183 43 ;;
44 -s | --show )
fb711183 45 shift 2
46 shownote "$NOTE"
07d42c7a 47 exit
fb711183 48 ;;
3951cc3d 49 -r | --restore )
3951cc3d 50 shift 2
51 backup_restore $RDIR
52 exit
53 ;;
4cbcb39e 54 --sync )
da52e73a 55 # I'm forcing it because if you run it manually, chances are that you need to.
56 gitsync -f
57 shift
4cbcb39e 58 exit
59 ;;
fb711183 60 --userconf )
61 export_config
62 # shellcheck disable=SC2317
63 echo "config exported to \"$RCFILE\""
64 # shellcheck disable=SC2317
65 exit
66 ;;
1f4d7742 67 --showconf )
68 configtext
69 exit
70 ;;
9eb02251 71 --backup )
9eb02251 72 shift 2
73 backup_data $BDIR
74 exit
75 ;;
fb711183 76 -- )
77 shift
78 break
79 ;;
80 * )
81 break
82 ;;
83 esac
84done
efa3e607 85
86for arg; do
87 if [ $(check_noteID $arg) ]; then
88 shownote $arg
89 else
90 helptext
91 exit
92 fi
93done