aboutsummaryrefslogtreecommitdiffstats
path: root/SOURCE/main.sh
blob: 147d90e081d13b54dabea121e8a2635c7f9f0ce0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# shellcheck disable=SC2006
GOPT=$(getopt -o hvplr:a::e:d:s: --long help,version,list,plain,userconf,showconf,sync,restore:,backup:,add::,edit:,delete:,show: -n 'bash-notes' -- "$@")

# shellcheck disable=SC2181
if [ $? != 0 ] ; then helptext >&2 ; exit 1 ; fi

# Note the quotes around `$GOPT': they are essential!
eval set -- "$GOPT"
unset GOPT

while true; do
	case "$1" in
	  	-h | --help )
			helptext
	        exit
	        ;;
		-v | --version )
			echo $BASENAME v${VERSION}
			exit
			;;
	    -p | --plain )
			PLAIN=true
			shift
	        ;;
	    -l | --list )
			listnotes
			exit
	        ;;
	    -a | --add )
			TITLE=$2
			shift 2
			addnote "$TITLE"
			exitwait
	        ;;
		-e | --edit )
			NOTE=$2
			shift 2
			editnote "$NOTE"
			exitwait
			;;
		-d | --delete )
			NOTE=$2
			shift 2
			rmnote "$NOTE"
			exitwait
			;;
		-s | --show )
			NOTE=$2
			shift 2
			shownote "$NOTE"
			exitwait
			;;
		-r | --restore )
			RDIR=$2
			shift 2
			backup_restore $RDIR
			exit
			;;
		--sync )
			# I'm forcing it because if you run it manually, chances are that you need to.
			gitsync -f
			shift
			exit
			;;
		--userconf )
			export_config
			# shellcheck disable=SC2317
			echo "config exported to \"$RCFILE\""
			# shellcheck disable=SC2317
			exit
			;;
		--showconf )
			configtext
			exit
			;;
		--backup )
			BDIR=$2
			shift 2
			backup_data $BDIR
			exit
			;;
		-- )
			shift
			break
			;;
		* )
			break
			;;
	esac
done

for arg; do
	if [ $(check_noteID $arg) ]; then
		shownote $arg
	else
		helptext
		exit
	fi
done