Skip to content

Instantly share code, notes, and snippets.

@bonny
Last active January 20, 2022 16:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bonny/c475c21bad4d1627e720abed6b525d50 to your computer and use it in GitHub Desktop.
Save bonny/c475c21bad4d1627e720abed6b525d50 to your computer and use it in GitHub Desktop.
xbar script for watson
#!/usr/bin/env bash
# Watson Brew Status
#
# by Antoine Corcy <contact@sbin.dk>
# updated by Pär Thernstrom <par.thernstrom@gmail.com>
# to support Watson custom location and configuration.
#
# <xbar.title>Watson Brew Status</xbar.title>
# <xbar.version>1.0</xbar.version>
# <xbar.author>Antoine Corcy</xbar.author>
# <xbar.author.github>toin0u</xbar.author.github>
# <xbar.desc>Shows Watson's status when installed from Brew</xbar.desc>
# <xbar.dependencies>Watson</xbar.dependencies>
# <xbar.image>https://i.imgur.com/3OuXrWn.png</xbar.image>
#
# Dependencies:
# watson (http://tailordev.github.io/Watson/)
# Needed because we have changed the config dir.
export WATSON_DIR="/Users/bonny/Google Drive/Application Settings/watson"
export WATSON_BIN="/opt/homebrew/bin/watson"
export JQ_BIN="/opt/homebrew/bin/jq"
# Stop command.
if [[ $1 = "stop" ]]
then
$($WATSON_BIN stop)
#echo "STOP" >> script.log
exit
fi
# Restart command.
if [[ $1 = "restart" ]]
then
$($WATSON_BIN restart)
#echo "restart" >> script.log
exit
fi
# Name of current project.
# "No project started". if no projected started.
current_project=$($WATSON_BIN status -p)
# List of all projects.
#all_projects=$($WATSON_BIN projects)
# Tags of current project, "[xbar, plugin]".
# Empty if no tags.
current_project_tags=$($WATSON_BIN status -t)
# Get the full status text.
# "Project Watson [xbar, plugin] started just now (2021.10.08 06:59:32+0200)"
status=$($WATSON_BIN status)
# Get day report and log.
# Note: We replace <tab> with "Braille Pattern Blank"
# (i.e. a char that looks like a space) to indent the text
# because a space or tab does not work for some reason.
day_report="$($WATSON_BIN report --day --no-pager --current)"
day_log="$($WATSON_BIN log --day --no-pager --current)"
week_log="$($WATSON_BIN log --no-pager --current)"
# Get name of last project
last_project_name="$($WATSON_BIN log --json | $JQ_BIN --raw-output '.[-1].project')"
# get the started time and uppercase the sentence
started=$(echo "$status" | grep -E -o 'started (.*) \(')
started="$(tr '[:lower:]' '[:upper:]' <<< "${started:0:1}")${started:1}"
# Get the tags
# tags=$(echo "$status" | awk '{printf "Tags: %s\n", $3}')
# Bail if no project is started.
if [[ "$current_project" == "No project start"* ]]
then
echo "⏱ No project | color=#999999"
# exit
else
echo "⏱ $current_project"
echo "---"
echo "Project: $current_project"
if [[ $current_project_tags ]]
then
echo "Tags: $current_project_tags"
fi
# echo "Open terminal | shell=open | param1=/System/Applications/Utilities/Terminal.app"
echo "---"
echo "${started/(/} | color=green"
echo "Stop | shell=$0 | refresh=true | param1=stop"
fi
# Always stop restart and reports
echo "---"
echo "Restart last project ($last_project_name) | shell=$0 | refresh=true | param1=restart"
# Get the n latest project names.
latest_projects=$($WATSON_BIN log --csv | awk -F ',' '{printf $4"\n"}' | uniq | sed '/^$/d' | tail -r -n 5)
echo "Start recent project"
echo "$latest_projects" | awk '$0="--"$0'
echo "---"
# Summary and log of day.
# Each sub item is prefixed with "--" using awk.
echo "Day report"
echo "$day_report" | awk '$0="--"$0" | color=black | trim=false | font=Menlo"'
echo "Day log"
echo "$day_log" | awk '$0="--"$0" | color=black | trim=false | font=Menlo"'
echo "Last 7 days"
echo "$week_log" | awk '$0="--"$0" | color=black | trim=false | font=Menlo"'
#echo "Projects"
#echo "$all_projects" | awk '$0="--"$0" | color=black"'
@bonny
Copy link
Author

bonny commented Jan 20, 2022

Screenshot:

CleanShot 2022-01-20 at 14 22 33@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment