Skip to content

Commit

Permalink
feat: allow marks to be chosen using choose(1)
Browse files Browse the repository at this point in the history
  • Loading branch information
shalomb committed Nov 2, 2024
1 parent 4d8f479 commit 15994d3
Show file tree
Hide file tree
Showing 16 changed files with 408 additions and 700 deletions.
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; https://editorconfig.org/

root = true

[*]
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[{Makefile,go.mod,go.sum,*.go,.gitmodules}]
indent_style = tab
indent_size = 4

[*.md]
indent_size = 4
trim_trailing_whitespace = false

eclint_indent_style = unset

[Dockerfile]
indent_size = 4
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ clean: build-env tidy
rm -vf "$(APPNAME)"-*

tidy:
go get -u ./... # Upgrade all packages
go mod tidy

build-env:
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**unmarked 🎯**
---

Similar to [`harpoon`](https://github.com/ThePrimeagen/harpoon), unmarked is the keyboard user's tool for switching to windows
just using their marks.
Expand Down Expand Up @@ -40,6 +41,7 @@ terminal, press `ctrl-alt-f` to focus firefox, etc.
No need to `alt-tab` or reach for the mouse - Win! 🏆

**why? 💡**
---

My workflow usually involves making some code edits in neovim in wezterm,
switching to firefox to test, moving to jira to making some comments, moving
Expand All @@ -52,6 +54,7 @@ With unmarked, simply pressing `ctrl-alt-<mnemonic>` is enough to get me back
into the app and back on track.

**Building 🛠️**
---

Requires `go` >= 1.19, yabai, skhd

Expand All @@ -62,3 +65,23 @@ export PATH="$HOME/.bin:$PATH"

unmarked help
```
**Debugging 🐞**
---

Ensure `unmarked` is installed into a directory of `$PATH
`
```shell
unmarked version
```

Run `skhd` in debugging mode and test keyboard input

```shell
pkill skhd
skhd -V

# when complete with debugging, restart the skhd service
skhd --start-service
```

Refer to [`skhd`'s documentation](https://github.com/koekeishiya/skhd/issues/1) on how to discover keycodes.
81 changes: 81 additions & 0 deletions choosecmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package main

import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(chooseMarksCmd)
}

// markCmd represents the mark command
var chooseMarksCmd = &cobra.Command{
Use: "choose",
Short: "Choose from available marked windows",
Long: `Choose from all the marked windows`,
Run: func(_ *cobra.Command, _ []string) {
log.Printf("choosing marks under %v", stateHome)
chooseMarks()
},
}

func chooseMarks() {
matches, _ := filepath.Glob(fmt.Sprintf("%s/*", stateHome))
lines := []string{}
for _, match := range matches {
f, _ := os.Stat(match)
if !f.IsDir() {
data, err := os.ReadFile(match)
if err != nil {
log.Printf("ERROR: could not read file", match)
}

app, err := jq(".app", string(data))
if err != nil {
log.Printf("Could not find .app under %v", data)
}

title, err := jq(".title", string(data))
if err != nil {
log.Printf("Could not find .title under %v", data)
}

line := fmt.Sprintf("%s -> %s [%s]\n", filepath.Base(match), title, app)
lines = append(lines, line)
}
}

chooseCmd := exec.Command(
"choose", "-n", "20", "-s", "20", "-b", "fac898",
"-c", "FF7518", "-p", "Choose a mark")
chooseIn, _ := chooseCmd.StdinPipe()
chooseOut, _ := chooseCmd.StdoutPipe()

chooseCmd.Start()
chooseIn.Write([]byte(strings.Join(lines, "\n")))
chooseIn.Close()

chooseBytes, _ := io.ReadAll(chooseOut)
chooseCmd.Wait()

choice := string(chooseBytes)
if len(choice) == 0 {
log.Fatalf("No/empty response from choose, aborting", choice)
}

mark := string(choice[0])
if len(mark) == 0 {
log.Fatalf("Error deriving mark (%v) from choose (%v)", mark, choice)
}

m := NewWinMarker()
m.SummonMark(mark)
}
43 changes: 23 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
module github.com/shalomb/unmarked

go 1.19
go 1.22.0

toolchain go1.23.0

require (
github.com/MakeNowJust/heredoc v1.0.0
github.com/adrg/xdg v0.4.0
github.com/itchyny/gojq v0.12.9
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
github.com/adrg/xdg v0.5.3
github.com/itchyny/gojq v0.12.16
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.14.0
github.com/spf13/viper v1.19.0
)

require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/itchyny/timefmt-go v0.1.4 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/itchyny/timefmt-go v0.1.6 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 15994d3

Please sign in to comment.