fix(selector): allow logging errors

This commit is contained in:
yory8 2019-05-09 18:46:16 +02:00
parent 0a00dede30
commit 970e8ad514
2 changed files with 12 additions and 4 deletions

View file

@ -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