feat: add restore command to serve last item

This commit is contained in:
yory8 2019-10-27 09:13:44 +01:00
parent 6b604f2ef2
commit 676fea9c99

16
main.go
View file

@ -33,6 +33,8 @@ var (
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()
restorer = app.Command("restore", "Serve the last recorded item from history")
)
func main() {
@ -78,6 +80,20 @@ func main() {
log.Fatal(err)
}
}
case "restore":
_, history, err := getHistory(*histpath)
if err != nil {
log.Fatal(err)
}
if len(history) == 0 {
log.Println("Nothing to restore")
return
}
if err := exec.Command("wl-copy", "--", history[len(history)-1]).Run(); err != nil {
log.Fatal(err)
}
case "clear":
histfile, history, err := getHistory(*histpath)
if err != nil {