feat(selector): add --tool-args to pass extra argument to the --tool

This commit is contained in:
Eric Engestrom 2019-10-14 08:40:00 +01:00 committed by yory8
parent f5ed53d378
commit fca660c42f
2 changed files with 14 additions and 10 deletions

20
main.go
View file

@ -23,14 +23,16 @@ var (
maxDemon = storer.Flag("max-items", "history size").Default("15").Int() maxDemon = storer.Flag("max-items", "history size").Default("15").Int()
noPersist = storer.Flag("no-persist", "Don't persist a copy buffer after a program exits").Short('P').Default("false").Bool() noPersist = storer.Flag("no-persist", "Don't persist a copy buffer after a program exits").Short('P').Default("false").Bool()
picker = app.Command("pick", "Pick an item from clipboard history") picker = app.Command("pick", "Pick an item from clipboard history")
maxPicker = picker.Flag("max-items", "scrollview length").Default("15").Int() maxPicker = picker.Flag("max-items", "scrollview length").Default("15").Int()
pickTool = picker.Flag("tool", "Which selector to use: dmenu/rofi/wofi/STDOUT").Short('t').Default("dmenu").String() pickTool = picker.Flag("tool", "Which selector to use: dmenu/rofi/wofi/STDOUT").Short('t').Default("dmenu").String()
pickToolArgs = picker.Flag("tool-args", "Extra arguments to pass to the --tool").Short('T').Default("").String()
clearer = app.Command("clear", "Remove item(s) from history") clearer = app.Command("clear", "Remove item(s) from history")
maxClearer = clearer.Flag("max-items", "scrollview length").Default("15").Int() maxClearer = clearer.Flag("max-items", "scrollview length").Default("15").Int()
clearTool = clearer.Flag("tool", "Which selector to use: dmenu/rofi/wofi/STDOUT").Short('t').Default("dmenu").String() clearTool = clearer.Flag("tool", "Which selector to use: dmenu/rofi/wofi/STDOUT").Short('t').Default("dmenu").String()
clearAll = clearer.Flag("all", "Remove all items").Short('a').Default("false").Bool() clearToolArgs = clearer.Flag("tool-args", "Extra arguments to pass to the --tool").Short('T').Default("").String()
clearAll = clearer.Flag("all", "Remove all items").Short('a').Default("false").Bool()
) )
func main() { func main() {
@ -65,7 +67,7 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
selection, err := selector(history, *maxPicker, *pickTool, "pick") selection, err := selector(history, *maxPicker, *pickTool, "pick", *pickToolArgs)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -90,7 +92,7 @@ func main() {
return return
} }
selection, err := selector(history, *maxClearer, *clearTool, "clear") selection, err := selector(history, *maxClearer, *clearTool, "clear", *clearToolArgs)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View file

@ -9,7 +9,7 @@ import (
"strings" "strings"
) )
func selector(data []string, max int, tool string, prompt string) (string, error) { func selector(data []string, max int, tool string, prompt string, toolsArgs string) (string, error) {
if len(data) == 0 { if len(data) == 0 {
return "", errors.New("nothing to show: no data available") return "", errors.New("nothing to show: no data available")
} }
@ -44,6 +44,8 @@ func selector(data []string, max int, tool string, prompt string) (string, error
return "", fmt.Errorf("Unsupported tool: %s", tool) return "", fmt.Errorf("Unsupported tool: %s", tool)
} }
args = append(args, strings.Fields(toolsArgs)...)
processed, guide := preprocessData(data, true, false) processed, guide := preprocessData(data, true, false)
cmd := exec.Cmd{Path: bin, Args: args, Stdin: strings.NewReader(strings.Join(processed, "\n"))} cmd := exec.Cmd{Path: bin, Args: args, Stdin: strings.NewReader(strings.Join(processed, "\n"))}