-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow marks to be chosen using choose(1)
- Loading branch information
Showing
16 changed files
with
408 additions
and
700 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Oops, something went wrong.