initial setup of git functionality. The program can now initalize a local repo and...
[bash-notes.git] / SOURCE / main.sh
CommitLineData
fb711183 1# shellcheck disable=SC2006
4cbcb39e 2GOPT=$(getopt -o hvplr::a::e::d::s:: --long help,version,list,plain,userconf,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 )
95 gitsync
96 exit
97 ;;
fb711183 98 --userconf )
99 export_config
100 # shellcheck disable=SC2317
101 echo "config exported to \"$RCFILE\""
102 # shellcheck disable=SC2317
103 exit
104 ;;
9eb02251 105 --backup )
106 case "$2" in
107 '' )
108 read -r -p "Backup Dir: " BDIR
109 ;;
110 * )
111 BDIR=$2
112 ;;
113 esac
114 shift 2
115 backup_data $BDIR
116 exit
117 ;;
fb711183 118 -- )
119 shift
120 break
121 ;;
122 * )
123 break
124 ;;
125 esac
126done
efa3e607 127
128for arg; do
129 if [ $(check_noteID $arg) ]; then
130 shownote $arg
131 else
132 helptext
133 exit
134 fi
135done