aboutsummaryrefslogtreecommitdiff
path: root/timebutler.sh
blob: e45c461a8cf41d8d7863773e99ec746d0036f375 (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
#!env bash
# Minimalist Timebutler CLI interface 
# ./timebutler start|pause|resume|stop|cancel|status [project]
# You have to set USERID and AUTH variables in ~/.timebutler!
# Run `curl -X POST 'https://timebutler.de/api/v1/users' -d "auth=$AUTH"` to fetch user ids.
set -e

. ~/.timebutler
test -n "$AUTH" -a -n "$USERID"

COMMAND=$1
if [ -z "$COMMAND" ]; then
	echo "Missing command"
	exit 1
fi

PROJECT=$2
if [ -n "$PROJECT" ]; then
	PROJECTID=(`curl -s -X POST 'https://timebutler.de/api/v1/projects' -d "auth=$AUTH" | awk -F ';' "\\$2~/$PROJECT/ {print \\$1}"`)
	if [ ${#PROJECTID[*]} != 1 ]; then
		echo "Unknown or ambiguous project \"$PROJECT\""
		exit 1
	fi
	ARGS="$ARGS -d projectid=$PROJECTID"
fi

exec curl -X POST 'https://timebutler.de/api/v1/timeclock' -d "auth=$AUTH" -d "userid=$USERID" -d "command=$COMMAND" $ARGS