From 11c0931778d4d05d9fbbd8bf02ac99203554b527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kenneth=20S=C3=B6derlund?= Date: Thu, 24 Jul 2025 13:28:54 +0300 Subject: [PATCH] fix: improve docs and version output Update README to include installation steps. Update the version command to display the information in a table. --- README.md | 77 +++++++++++++++++++++++++++++++++++++++++++- cmd/version.go | 49 ++++++++++++++++++---------- examples/config.json | 55 +++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+), 18 deletions(-) create mode 100644 examples/config.json diff --git a/README.md b/README.md index 1e35da4..763f684 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,82 @@ mimic the way i3wm handles the scratchpad. # Installation +## Go install + Run `go install github.com/soderluk/nirimgr@latest` to install nirimgr. +## From GitHub Releases + +Get the latest release from the [Releases page](https://github.com/soderluk/nirimgr/releases/). + +Choose your arch and download the tarball. + +If you want to verify the download, also get the `nirimgr_x.x.x_checksums.txt` file. + +To verify the download run `sha256sum -c [checksums.txt]` + +```bash +$ sha256sum -c nirimgr_x.x.x_checksums.txt + +sha256sum: nirimgr_x.x.x_darwin_amd64.tar.gz: No such file or directory +nirimgr_x.x.x_darwin_amd64.tar.gz: FAILED open or read +sha256sum: nirimgr_x.x.x_darwin_arm64.tar.gz: No such file or directory +nirimgr_x.x.x_darwin_arm64.tar.gz: FAILED open or read +nirimgr_x.x.x_linux_amd64.tar.gz: OK +sha256sum: WARNING: 2 listed files could not be read +``` + +If you only downloaded one tarball, you'll get 2 failures on the checks. If you have 3 failed checks, +please make sure you downloaded the tarball from https://github.com/soderluk/nirimgr/releases/. + +If things are still failing, please open an [issue](https://github.com/soderluk/nirimgr/issues/new). + +After verification succeeds, unzip the tarball somewhere, e.g. ~/Downloads/nirimgr. + +```bash +tar xf nirimgr_x.x.x_linux_amd64.tar.gz --directory=~/Downloads/nirimgr/ +``` + +The tarball includes the following files: + +- CHANGELOG.md: The changelog for this version. +- LICENSE: The license file of the repository. +- nirimgr: The executable file. +- README.md: This readme. + +Move the `nirimgr` executable somewhere in your `PATH`, e.g. `/usr/local/bin`, or `~/bin`. + +Verify the version after installation: + +`nirimgr version` + +```bash +$ nirimgr version + +┌──────────────┬────────────────────────────────────────────┐ +│ NIRIMGR │ │ +├──────────────┼────────────────────────────────────────────┤ +│ Version │ 0.1.2 │ +│ Commit │ a86e7ad8bbea61b56ab8a2ee7eeea1e6aa30bfe9 │ +│ Build Date │ 2025-07-24T08:24:50Z │ +│ ---------- │ ---------- │ +│ Build Info │ │ +│ ---------- │ ---------- │ +│ Go version │ go1.23.5 │ +│ -buildmode │ exe │ +│ -compiler │ gc │ +│ -trimpath │ true │ +│ CGO_ENABLED │ 0 │ +│ CGO_CFLAGS │ │ +│ CGO_CPPFLAGS │ │ +│ CGO_CXXFLAGS │ │ +│ CGO_LDFLAGS │ │ +│ GOARCH │ amd64 │ +│ GOOS │ linux │ +│ GOAMD64 │ v1 │ +└──────────────┴────────────────────────────────────────────┘ +``` + # Configuration The configuration file for nirimgr should be put in ~/.config/nirimgr/config.json @@ -108,7 +182,7 @@ Please feel free to open a PR if you have other thoughts that we could do with n # Usage -To use nirimgr, it provides two CLI-commands: +To use nirimgr, it provides the following CLI-commands: - `events`: The events command starts listening on the niri event-stream. `nirimgr events` - `scratch`: The scratch command moves a window to the scratchpad workspace, or shows the window (moves the window @@ -116,6 +190,7 @@ To use nirimgr, it provides two CLI-commands: as a keybind in niri configuration. `nirimgr scratch [move|show]` - `list`: The list command will list all the available actions or events, so you don't need to remember them all. `nirimgr list [actions|events]` +- `version`: The version command prints the nirimgr version information. `nirimgr version` To use the scratchpad with Niri, you need to have a named workspace `scratchpad`, or if you want to configure it, set the scratchpadWorkspace configuration option to something else `"scratchpadWorkspace": "scratch"`. diff --git a/cmd/version.go b/cmd/version.go index 473f8bc..8b7c6fc 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -2,9 +2,12 @@ package cmd import ( "fmt" + "os" "runtime" "runtime/debug" + "strings" + "github.com/olekukonko/tablewriter" "github.com/soderluk/nirimgr/config" "github.com/spf13/cobra" ) @@ -15,26 +18,38 @@ var versionCmd = &cobra.Command{ Short: "Print version", Long: "Prints the version number and build information about nirimgr", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("nirimgr " + buildInfo()) + table := tablewriter.NewTable(os.Stdout) + table.Header([]string{"nirimgr", ""}) + c := 10 + info := [][]string{ + {"Version", config.Version}, + {"Commit", config.CommitSHA}, + {"Build Date", config.BuildDate}, + {r("-", c), r("-", c)}, + {"Build Info", ""}, + {r("-", c), r("-", c)}, + {"Go version", runtime.Version()}, + } + bi, _ := debug.ReadBuildInfo() + for _, s := range bi.Settings { + info = append(info, []string{s.Key, s.Value}) + } + for _, data := range info { + if err := table.Append(data[0], data[1]); err != nil { + fmt.Printf("Could not append %s to info\n", data[0]) + } + } + if err := table.Render(); err != nil { + fmt.Println("Could not render table.") + } }, } -func init() { - rootCmd.AddCommand(versionCmd) +// r returns the repeated string s, count c times. +func r(s string, c int) string { + return strings.Repeat(s, c) } -// buildInfo returns the build information about nirimgr -func buildInfo() string { - info := fmt.Sprintf("\nVersion:\t%s\nCommit:\t%s\nGo Version:\t%s\nBuild Date:\t%s\nBuild info: \n", - config.Version, - config.CommitSHA, - runtime.Version(), - config.BuildDate, - ) - bi, _ := debug.ReadBuildInfo() - for _, setting := range bi.Settings { - info += fmt.Sprintf("%s:\t%s\n", setting.Key, setting.Value) - } - - return info +func init() { + rootCmd.AddCommand(versionCmd) } diff --git a/examples/config.json b/examples/config.json new file mode 100644 index 0000000..dc07e97 --- /dev/null +++ b/examples/config.json @@ -0,0 +1,55 @@ +{ + "scratchpadWorkspace": "scratchpad", + "logLevel": "DEBUG", + "rules": [ + { + "match": [ + { + "title": "Bitwarden", + "appId": "zen" + } + ], + "actions": { + "MoveWindowToFloating": {}, + "SetWindowWidth": { + "change": { + "SetFixed": 400 + } + }, + "SetWindowHeight": { + "change": { + "SetFixed": 600 + } + } + } + }, + { + "match": [ + { + "appId": "org.gnome.Calculator" + } + ], + "actions": { + "MoveWindowToFloating": {}, + "MoveFloatingWindow": { + "x": { + "SetFixed": 800 + }, + "y": { + "SetFixed": 200 + } + }, + "SetWindowWidth": { + "change": { + "SetFixed": 50 + } + }, + "SetWindowHeight": { + "change": { + "SetFixed": 50 + } + } + } + } + ] +}