This commit is contained in:
2025-03-07 12:32:22 +01:00
parent 0dd48c7d57
commit 541804e139

View File

@@ -3,6 +3,28 @@
A simple plugin for [Starship](https://github.com/starship/starship), A simple plugin for [Starship](https://github.com/starship/starship),
which shows the elapsed time of the current [watson](https://github.com/jazzband/Watson) project. which shows the elapsed time of the current [watson](https://github.com/jazzband/Watson) project.
## Why?
Unfortunately `watson status` itself is just too verbose. I only need
the hours elapsed. Manipulating the output were too slow, it lead to a partially hanging prompt.
I tried several variants, among these:
```toml
# using sed
command = "watson status -e | sed -e 's/ ago//' -e 's/ seconds/s/' -e 's/ minutes/m/' -e 's/ hours/h/' -e 's/just now/0/'"
# use perl to parse the status file directly
command = 'perl -n -e "if (/start.: (\d+)/) { \$diff = (time - \$1) / 3600; printf \"%.02fh\n\", \$diff; }" < ~/.config/watson/state'
# use bash, date and https://github.com/TLINDEN/rpnc direclty on the status file
command = 'if [[ "$(grep start ~/.config/watson/state)" =~ ([0-9]+) ]]; then echo $(("$(date +%s)" - "${BASH_REMATCH[1]}")) 3600 / | rpn; fi'
```
This lille tool here is written in go, reasonably fast, it parses the
watson JSON status file directly, calculates the elapsed time since
the start of the running project and prints it. Pretty simple.
## Setup ## Setup
You'll need the Golang toolchain for this (version 1.23+). You'll need the Golang toolchain for this (version 1.23+).