2021-03-17 14:59:32 +00:00
|
|
|
#!/bin/sh
|
2021-03-16 22:49:01 +00:00
|
|
|
|
|
|
|
# <xbar.title>zeit</xbar.title>
|
|
|
|
# <xbar.author>Marius</xbar.author>
|
|
|
|
# <xbar.author.github>mrusme</xbar.author.github>
|
|
|
|
# <xbar.desc>Control `zeit` (https://github.com/mrusme/zeit) from the macOS menu bar.</xbar.desc>
|
|
|
|
# <xbar.image>https://github.com/mrusme/zeit/raw/main/documentation/zeit.png</xbar.image>
|
|
|
|
# <xbar.abouturl>https://マリウス.com/zeit-erfassen-a-cli-activity-time-tracker/</xbar.abouturl>
|
|
|
|
# <xbar.version>1.0</xbar.version>
|
|
|
|
#
|
|
|
|
# <xbar.var>string(ZEIT_BIN="/usr/local/bin/zeit"): Your zeit binary location</xbar.var>
|
|
|
|
# <xbar.var>string(ZEIT_DB="$HOME/.zeit.db"): Your zeit database location</xbar.var>
|
|
|
|
#
|
|
|
|
# Control `zeit` (https://github.com/mrusme/zeit) from the macOS menu bar.
|
|
|
|
#
|
|
|
|
# by Marius (marius@xn--gckvb8fzb.com)
|
|
|
|
#
|
|
|
|
|
2021-03-17 14:59:32 +00:00
|
|
|
PLACEHOLDER_NO_PROJECT='[no project]'
|
|
|
|
PLACEHOLDER_NO_TASK='[no task]'
|
|
|
|
|
2021-03-18 15:21:02 +00:00
|
|
|
if [ -z "$ZEIT_BIN" ]
|
2021-03-17 14:59:32 +00:00
|
|
|
then
|
|
|
|
ZEIT_BIN=$1
|
|
|
|
fi
|
|
|
|
|
2021-03-18 15:21:02 +00:00
|
|
|
if [ -z "$ZEIT_DB" ]
|
2021-03-17 14:59:32 +00:00
|
|
|
then
|
|
|
|
export ZEIT_DB=$2
|
|
|
|
fi
|
|
|
|
|
|
|
|
case $3 in
|
|
|
|
"track")
|
|
|
|
flag_p=$4
|
|
|
|
flag_t=$5
|
|
|
|
|
|
|
|
$ZEIT_BIN --no-colors finish
|
|
|
|
|
2021-03-18 15:21:02 +00:00
|
|
|
if [ "$flag_p" = "$PLACEHOLDER_NO_PROJECT" ]
|
2021-03-17 14:59:32 +00:00
|
|
|
then
|
|
|
|
flag_p=''
|
|
|
|
fi
|
2021-03-18 15:21:02 +00:00
|
|
|
if [ "$flag_t" = "$PLACEHOLDER_NO_TASK" ]
|
2021-03-17 14:59:32 +00:00
|
|
|
then
|
|
|
|
flag_t=''
|
|
|
|
fi
|
|
|
|
|
|
|
|
$ZEIT_BIN --no-colors track -p "$flag_p" -t "$flag_t"
|
|
|
|
# exit 0
|
|
|
|
;;
|
|
|
|
"finish")
|
|
|
|
$ZEIT_BIN --no-colors finish
|
|
|
|
# exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
trackingProject=''
|
|
|
|
trackingTask=''
|
|
|
|
trackingDuration=''
|
|
|
|
tracking=$($ZEIT_BIN --no-colors tracking)
|
|
|
|
|
2021-03-18 15:21:02 +00:00
|
|
|
if echo "$tracking" | grep -q '^ ▶ tracking'
|
2021-03-17 14:59:32 +00:00
|
|
|
then
|
2021-03-18 15:21:02 +00:00
|
|
|
if echo "$tracking" | grep -q '^ ▶ tracking task for'
|
2021-03-17 14:59:32 +00:00
|
|
|
then
|
|
|
|
trackingProject=$PLACEHOLDER_NO_PROJECT
|
|
|
|
trackingTask=$PLACEHOLDER_NO_TASK
|
2021-03-18 15:21:02 +00:00
|
|
|
trackingDuration=$(echo "$tracking" | sed -E 's/.*tracking task for (.+)/\1/g')
|
2021-03-17 14:59:32 +00:00
|
|
|
else
|
2021-03-18 15:21:02 +00:00
|
|
|
trackingProject=$(echo "$tracking" | sed -E 's/.*tracking (.+) on (.+) for (.+)/\2/g')
|
|
|
|
trackingTask=$(echo "$tracking" | sed -E 's/.*tracking (.+) on (.+) for (.+)/\1/g')
|
|
|
|
trackingDuration=$(echo "$tracking" | sed -E 's/.*tracking (.+) on (.+) for (.+)/\3/g')
|
2021-03-17 14:59:32 +00:00
|
|
|
fi
|
|
|
|
tracking=$trackingDuration
|
|
|
|
fi
|
|
|
|
|
2021-03-18 15:21:02 +00:00
|
|
|
echo "$tracking"
|
2021-03-17 14:59:32 +00:00
|
|
|
echo '---'
|
|
|
|
echo 'Projects'
|
|
|
|
|
|
|
|
project=''
|
2021-03-18 15:21:02 +00:00
|
|
|
$ZEIT_BIN --no-colors list --only-projects-and-tasks | while read -r line
|
2021-03-17 14:59:32 +00:00
|
|
|
do
|
2021-03-18 15:21:02 +00:00
|
|
|
if echo "$line" | grep -q '^◆'
|
2021-03-17 14:59:32 +00:00
|
|
|
then
|
2021-03-18 15:21:02 +00:00
|
|
|
project=$(echo "$line" | sed 's/◆[[:space:]]\{0,3\}//g')
|
|
|
|
if [ "$project" = "" ]
|
2021-03-17 14:59:32 +00:00
|
|
|
then
|
|
|
|
project=$PLACEHOLDER_NO_PROJECT
|
|
|
|
fi
|
|
|
|
|
2021-03-18 15:21:02 +00:00
|
|
|
if [ "$project" = "$trackingProject" ]
|
2021-03-17 14:59:32 +00:00
|
|
|
then
|
|
|
|
echo "-- ▶ $project"
|
|
|
|
else
|
|
|
|
echo "-- $project"
|
|
|
|
fi
|
2021-03-18 15:21:02 +00:00
|
|
|
elif echo "$line" | grep -q '^└──'
|
2021-03-17 14:59:32 +00:00
|
|
|
then
|
2021-03-18 15:21:02 +00:00
|
|
|
task=$(echo "$line" | sed 's/└──[[:space:]]\{0,3\}//g')
|
2021-03-17 14:59:32 +00:00
|
|
|
|
2021-03-18 15:21:02 +00:00
|
|
|
if [ "$task" = "" ]
|
2021-03-17 14:59:32 +00:00
|
|
|
then
|
|
|
|
task=$PLACEHOLDER_NO_TASK
|
|
|
|
fi
|
|
|
|
|
2021-03-18 15:21:02 +00:00
|
|
|
if [ "$project" = "$trackingProject" ] && [ "$task" = "$trackingTask" ]
|
2021-03-17 14:59:32 +00:00
|
|
|
then
|
|
|
|
echo "---- ▶ $task | shell='$0' param1='$ZEIT_BIN' param2='$ZEIT_DB' param3=finish param4='$project' param5='$task' terminal=false refresh=true"
|
|
|
|
else
|
|
|
|
echo "---- $task | shell='$0' param1='$ZEIT_BIN' param2='$ZEIT_DB' param3=track param4='$project' param5='$task' terminal=false refresh=true"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2021-03-16 22:49:01 +00:00
|
|
|
exit
|