aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/vdir/calcurse-vdirsyncer
blob: 2ac849ac43b29a38427f622421a274211a218676 (plain) (blame)
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
#!/bin/sh

set -e

usage() {
	echo "usage: calcurse-vdirsyncer vdir [-h] [-f] [-v] [-D] datadir"
	exit
}

set_vdir() {
	if [ ! -d "$1" ]; then
		echo "error: $1 is not a valid vdir directory."
		exit 1
	else
		VDIR="$1"
	fi
}

set_datadir() {
	if [ -z "$1" ]; then
		echo "error: no datadir specified."
		usage
	fi
	if [ ! -d "$1" ]; then
		echo "error: $1 is not a valid data directory."
		exit 1
	else
		DATADIR="$1"
		shift
	fi
}

if [ "$#" -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
	usage
fi

[ -d "$HOME/.calcurse" ] && DATADIR="$HOME/.calcurse" || DATADIR="${XDG_DATA_HOME:-$HOME/.local/share}/calcurse"
VERBOSE=""
FORCE=""

set_vdir "$1"
shift

while [ $# -gt 0 ]; do
	case "$1" in
			-D|--datadir)
				shift
				set_datadir "$1"
				shift
			;;
			-h|--help)
				usage
			;;
			-f|--force)
				FORCE="-f"
				shift
			;;
			-v|--verbose)
				VERBOSE="-v"
				shift
			;;
			*)
				echo "error: invalid argument $1"
				usage
			;;
	esac
done

calcurse-vdir export "$VDIR" -D "$DATADIR" "$FORCE" "$VERBOSE" && \
	vdirsyncer sync && \
	calcurse-vdir import "$VDIR" -D "$DATADIR" "$FORCE" "$VERBOSE"