From 676fea9c998bda532b54cdc2de61642b72d2e5f8 Mon Sep 17 00:00:00 2001 From: yory8 <> Date: Sun, 27 Oct 2019 09:13:44 +0100 Subject: [PATCH] feat: add `restore` command to serve last item --- main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.go b/main.go index e0dd11f..1a0c94f 100644 --- a/main.go +++ b/main.go @@ -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 {