working on the backup and backup restore functionalities.
[bash-notes.git] / SOURCE / main.sh
1 # shellcheck disable=SC2006
2 GOPT=$(getopt -o hvpla::e::d::s:: --long help,version,list,plain,userconf,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 case "$2" in
31 '' )
32 read -r -p "Title: " TITLE
33 ;;
34 * )
35 TITLE=$2
36 ;;
37 esac
38 shift 2
39 addnote "$TITLE"
40 exit
41 ;;
42 -e | --edit )
43 case "$2" in
44 '' )
45 read -r -p "Note ID: " NOTE
46 ;;
47 * )
48 NOTE=$2
49 ;;
50 esac
51 shift 2
52 editnote "$NOTE"
53 exit
54 ;;
55 -d | --delete )
56 case "$2" in
57 '' )
58 read -r -p "Note ID: " NOTE
59 ;;
60 * )
61 NOTE=$2
62 ;;
63 esac
64 shift 2
65 rmnote "$NOTE"
66 exit
67 ;;
68 -s | --show )
69 case "$2" in
70 '' )
71 read -r -p "Note ID: " NOTE
72 ;;
73 * )
74 NOTE=$2
75 ;;
76 esac
77 shift 2
78 shownote "$NOTE"
79 exit
80 ;;
81 --userconf )
82 export_config
83 # shellcheck disable=SC2317
84 echo "config exported to \"$RCFILE\""
85 # shellcheck disable=SC2317
86 exit
87 ;;
88 --backup )
89 case "$2" in
90 '' )
91 read -r -p "Backup Dir: " BDIR
92 ;;
93 * )
94 BDIR=$2
95 ;;
96 esac
97 shift 2
98 backup_data $BDIR
99 exit
100 ;;
101 -- )
102 shift
103 break
104 ;;
105 * )
106 break
107 ;;
108 esac
109 done