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")
|
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()
|
||||||
|
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()
|
clearAll = clearer.Flag("all", "Remove all items").Short('a').Default("false").Bool()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"))}
|
||||||
|
|
Loading…
Reference in a new issue