fix(selector): allow logging errors
This commit is contained in:
parent
0a00dede30
commit
970e8ad514
2 changed files with 12 additions and 4 deletions
12
selector.go
12
selector.go
|
@ -15,9 +15,12 @@ func selector(history []string, max int, tool string) error {
|
|||
|
||||
selected, err := dmenu(history, max, tool)
|
||||
if err != nil {
|
||||
// dmenu exits with error when no selection done
|
||||
if err.Error() == "exit status 1" {
|
||||
// dmenu exits with this error when no selection done
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// serve selection to the OS
|
||||
err = exec.Command("wl-copy", []string{"--", selected}...).Run()
|
||||
|
@ -30,6 +33,11 @@ func dmenu(list []string, max int, tool string) (string, error) {
|
|||
return "", nil
|
||||
}
|
||||
|
||||
bin, err := exec.LookPath("/usr/bin/" + tool)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("%s is not installed", tool)
|
||||
}
|
||||
|
||||
var args []string
|
||||
if tool == "dmenu" {
|
||||
args = []string{"dmenu", "-b",
|
||||
|
@ -62,7 +70,7 @@ func dmenu(list []string, max int, tool string) (string, error) {
|
|||
|
||||
input := strings.NewReader(strings.Join(reprList, "\n"))
|
||||
|
||||
cmd := exec.Cmd{Path: "/usr/bin/" + tool, Args: args, Stdin: input}
|
||||
cmd := exec.Cmd{Path: bin, Args: args, Stdin: input}
|
||||
selected, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
Loading…
Reference in a new issue