initial commit

This commit is contained in:
2025-03-07 12:22:35 +01:00
parent d64ab08b45
commit 72ebdb4569
5 changed files with 127 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
watson-starship

13
Makefile Normal file
View File

@@ -0,0 +1,13 @@
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)

59
README.md Normal file
View File

@@ -0,0 +1,59 @@
# watson-starship
A simple plugin for [Starship](https://github.com/starship/starship),
which shows the elapsed time of the current project.
## Setup
You'll need the Golang toolchain for this (version 1.23+).
To build:
```shell
git clone https://github.com/TLINDEN/watson-starship.git
cd watson-starship
make
make install
```
Then add this to your `~/.config/starship.toml`:
```toml
[custom.watson]
when = "watson status -e | grep -v 'No project'"
style = "green"
command = 'watson-starship'
format = '\[[$output]($style)\]'
```
And add `${custom.watson}\` to your global `format` setting.
## Getting help
Although I'm happy to hear from watson-starship users in private email, that's the
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.
## Copyright and license
This software is licensed under the GNU GENERAL PUBLIC LICENSE version 3.
## Authors
T.v.Dein <tom AT vondein DOT org>
## Project homepage
https://github.com/TLINDEN/watson-starship
## Copyright and License
Licensed under the GNU GENERAL PUBLIC LICENSE version 3.
## Author
T.v.Dein <tom AT vondein DOT org>

3
go.mod Normal file
View File

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

51
main.go Normal file
View File

@@ -0,0 +1,51 @@
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())
}