aboutsummaryrefslogtreecommitdiff
path: root/timebutler.sh
diff options
context:
space:
mode:
Diffstat (limited to 'timebutler.sh')
-rwxr-xr-xtimebutler.sh27
1 files changed, 27 insertions, 0 deletions
diff --git a/timebutler.sh b/timebutler.sh
new file mode 100755
index 0000000..e45c461
--- /dev/null
+++ b/timebutler.sh
@@ -0,0 +1,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