2 Commits

Author SHA1 Message Date
419464ccf9 moved to codeberg 2025-12-16 20:50:11 +01:00
T. von Dein
a91664c8c2 move to codeberg (#1) 2025-12-16 20:43:46 +01:00
4 changed files with 7 additions and 71 deletions

View File

@@ -1,13 +0,0 @@
tool = watson-starship
all: buildlocal
buildlocal:
CGO_LDFLAGS='-static' go build -tags osusergo,netgo -ldflags "-extldflags=-static -w" --trimpath -buildmode=pie -o $(tool)
strip --strip-all $(tool)
install: buildlocal
install -m 755 $(tool) $(HOME)/bin/
clean:
rm -rf $(tool)

View File

@@ -1,3 +1,6 @@
> [!CAUTION]
> This software is now being maintained on [Codeberg](https://codeberg.org/scip/watson-starship/).
# watson-starship
A simple plugin for [Starship](https://github.com/starship/starship),
@@ -17,7 +20,7 @@ command = "watson status -e | sed -e 's/ ago//' -e 's/ seconds/s/' -e 's/ minute
# 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
# use bash, date and https://codeberg.org/scip/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'
```
@@ -32,7 +35,7 @@ You'll need the Golang toolchain for this (version 1.23+).
To build:
```shell
git clone https://github.com/TLINDEN/watson-starship.git
git clone https://codeberg.org/scip/watson-starship.git
cd watson-starship
make
make install
@@ -57,7 +60,7 @@ best way for me to forget to do something.
In order to report a bug, unexpected behavior, feature requests or to
submit a patch, please open an issue on github:
https://github.com/TLINDEN/watson-starship/issues.
https://codeberg.org/scip/watson-starship/issues.
## Copyright and license
@@ -69,7 +72,7 @@ T.v.Dein <tom AT vondein DOT org>
## Project homepage
https://github.com/TLINDEN/watson-starship
https://codeberg.org/scip/watson-starship
## Copyright and License

3
go.mod
View File

@@ -1,3 +0,0 @@
module watson-starship
go 1.23

51
main.go
View File

@@ -1,51 +0,0 @@
package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"
"log"
)
const statsfile string = ".config/watson/state"
type Stats struct {
Project string `json:"project"`
Start int64 `json:"start"`
}
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if err != nil {
return false
}
return !info.IsDir()
}
func main() {
statsfile := filepath.Join(os.Getenv("HOME"), statsfile)
if !fileExists(statsfile) {
return
}
data, err := os.ReadFile(statsfile)
if err != nil {
log.Fatalf("Could not read watson stats file: %w", err)
}
var stats Stats
if err = json.Unmarshal(data, &stats); err != nil {
log.Fatalf("Could not unmarshal JSON: %w", err)
}
start := time.Unix(stats.Start, 0)
elapsed := time.Since(start)
fmt.Printf("%.02fh\n", elapsed.Hours())
}