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)
|
selected, err := dmenu(history, max, tool)
|
||||||
if err != nil {
|
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 nil
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// serve selection to the OS
|
// serve selection to the OS
|
||||||
err = exec.Command("wl-copy", []string{"--", selected}...).Run()
|
err = exec.Command("wl-copy", []string{"--", selected}...).Run()
|
||||||
|
@ -30,6 +33,11 @@ func dmenu(list []string, max int, tool string) (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bin, err := exec.LookPath("/usr/bin/" + tool)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("%s is not installed", tool)
|
||||||
|
}
|
||||||
|
|
||||||
var args []string
|
var args []string
|
||||||
if tool == "dmenu" {
|
if tool == "dmenu" {
|
||||||
args = []string{"dmenu", "-b",
|
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"))
|
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()
|
selected, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
Loading…
Reference in a new issue