feat(selector): add --tool-args to pass extra argument to the --tool
This commit is contained in:
parent
f5ed53d378
commit
fca660c42f
2 changed files with 14 additions and 10 deletions
6
main.go
6
main.go
|
@ -26,10 +26,12 @@ var (
|
|||
picker = app.Command("pick", "Pick an item from clipboard history")
|
||||
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()
|
||||
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")
|
||||
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()
|
||||
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()
|
||||
)
|
||||
|
||||
|
@ -65,7 +67,7 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
selection, err := selector(history, *maxPicker, *pickTool, "pick")
|
||||
selection, err := selector(history, *maxPicker, *pickTool, "pick", *pickToolArgs)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -90,7 +92,7 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
selection, err := selector(history, *maxClearer, *clearTool, "clear")
|
||||
selection, err := selector(history, *maxClearer, *clearTool, "clear", *clearToolArgs)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"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 {
|
||||
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)
|
||||
}
|
||||
|
||||
args = append(args, strings.Fields(toolsArgs)...)
|
||||
|
||||
processed, guide := preprocessData(data, true, false)
|
||||
|
||||
cmd := exec.Cmd{Path: bin, Args: args, Stdin: strings.NewReader(strings.Join(processed, "\n"))}
|
||||
|
|
Loading…
Reference in a new issue