mirror of
https://codeberg.org/scip/watson-starship.git
synced 2025-12-16 20:21:05 +01:00
+why
This commit is contained in:
22
README.md
22
README.md
@@ -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+).
|
||||||
|
|||||||
Reference in New Issue
Block a user