Separated script into multiple files for easier management. Added Makefile
[bash-notes.git] / SOURCE / main.sh
CommitLineData
fb711183 1# shellcheck disable=SC2006
2GOPT=$(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
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 )
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 ;;
41 -e | --edit )
42 case "$2" in
43 '' )
44 read -r -p "Note ID: " NOTE
45 ;;
46 * )
47 NOTE=$2
48 ;;
49 esac
50 shift 2
51 editnote "$NOTE"
52 ;;
53 -d | --delete )
54 case "$2" in
55 '' )
56 read -r -p "Note ID: " NOTE
57 ;;
58 * )
59 NOTE=$2
60 ;;
61 esac
62 shift 2
63 rmnote "$NOTE"
64 ;;
65 -s | --show )
66 case "$2" in
67 '' )
68 read -r -p "Note ID: " NOTE
69 ;;
70 * )
71 NOTE=$2
72 ;;
73 esac
74 shift 2
75 shownote "$NOTE"
76 ;;
77 --userconf )
78 export_config
79 # shellcheck disable=SC2317
80 echo "config exported to \"$RCFILE\""
81 # shellcheck disable=SC2317
82 exit
83 ;;
84 -- )
85 shift
86 break
87 ;;
88 * )
89 break
90 ;;
91 esac
92done
93
94if [ -z $1 ]; then
95 helptext
96fi