diff --git a/main.go b/main.go index bb7180d..6e92cdb 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,7 @@ var ( asSelector = app.Flag("select", "Select an item from clipboard history").Short('s').Default("false").Bool() noPersist = app.Flag("no-persist", "Don't persist a copy buffer after a program exits").Short('P').Default("false").Bool() max = app.Flag("max-items", "items to store in history (with -d) or display before scrolling (with -s)").Default("15").Int() - tool = app.Flag("selector", "Which selector to use: dmenu/rofi").Default("dmenu").String() + tool = app.Flag("selector", "Which selector to use: dmenu/rofi").Default("dmenu").String() ) func main() { diff --git a/selector.go b/selector.go index a01b8ac..5934887 100644 --- a/selector.go +++ b/selector.go @@ -15,8 +15,11 @@ 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 - return nil + if err.Error() == "exit status 1" { + // dmenu exits with this error when no selection done + return nil + } + return err } // serve selection to the OS @@ -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