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

@ -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() {

View file

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