added showconf option. Fixed bug that prevented the rc file from being correctly...
[bash-notes.git] / SOURCE / main.sh
CommitLineData
fb711183 1# shellcheck disable=SC2006
1f4d7742 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 )
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"
07d42c7a 40 exit
fb711183 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"
07d42c7a 53 exit
fb711183 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"
07d42c7a 66 exit
fb711183 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"
07d42c7a 79 exit
fb711183 80 ;;
3951cc3d 81 -r | --restore )
82 case "$2" in
83 '' )
84 read -r -p "Backup Dir: " RDIR
85 ;;
86 * )
87 RDIR=$2
88 ;;
89 esac
90 shift 2
91 backup_restore $RDIR
92 exit
93 ;;
4cbcb39e 94 --sync )
1f4d7742 95 case "$2" in
96 '' )
97 gitsync
98 ;;
99 '-f' )
100 gitsync -f
101 ;;
102 * )
103 helptext
104 exit
105 ;;
106 esac
107 shift 2
4cbcb39e 108 exit
109 ;;
fb711183 110 --userconf )
111 export_config
112 # shellcheck disable=SC2317
113 echo "config exported to \"$RCFILE\""
114 # shellcheck disable=SC2317
115 exit
116 ;;
1f4d7742 117 --showconf )
118 configtext
119 exit
120 ;;
9eb02251 121 --backup )
122 case "$2" in
123 '' )
124 read -r -p "Backup Dir: " BDIR
125 ;;
126 * )
127 BDIR=$2
128 ;;
129 esac
130 shift 2
131 backup_data $BDIR
132 exit
133 ;;
fb711183 134 -- )
135 shift
136 break
137 ;;
138 * )
139 break
140 ;;
141 esac
142done
efa3e607 143
144for arg; do
145 if [ $(check_noteID $arg) ]; then
146 shownote $arg
147 else
148 helptext
149 exit
150 fi
151done