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