diff --git a/BUILD.bazel b/BUILD.bazel index 5ccb520..e3bb93d 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -14,12 +14,13 @@ go_library( srcs = [ "config.go", "main.go", + "tui.go", ], importpath = "github.com/jotadrilo/rubbi-sh", visibility = ["//visibility:private"], deps = [ "//vendor/github.com/juju/errors:go_default_library", - "//vendor/github.com/mmikulicic/multierror:go_default_library", + "//vendor/github.com/manifoldco/promptui:go_default_library", ], ) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a5caff..63d5a96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ +## Release 0.1.0 (2019-06-26) + +- **Remove** `use` option +- Add **terminal interface** to the new `sel` option to prompt the list of folders and use the selected one +- **Adjust shell helpers** to work with this new feature + ## Release 0.0.14 (2019-06-25) -- Add Flush feature to remove entries in the configuration for absent folders +- **Add `Flush` feature** to remove entries in the configuration for absent folders ## Release 0.0.13 (2019-06-24) @@ -8,7 +14,7 @@ ## Release 0.0.12 (2019-06-15) -- Fix Hombrew formula +- Fix **Hombrew** formula - Fix alias files ## Release 0.0.11 (2019-06-15) diff --git a/dotfiles/.rubbi.sh b/dotfiles/.rubbi.sh index d5ef887..ea33335 100644 --- a/dotfiles/.rubbi.sh +++ b/dotfiles/.rubbi.sh @@ -20,11 +20,7 @@ function rubuse { rubbi-sh -use "${1}" } function rubsel { - rubbi-sh -show - echo - echo -n "Folder to use: " - read -r fn - rubbi-sh -use "$fn" + rubbi-sh -sel rubcd } function rbsh { diff --git a/go.mod b/go.mod index 371127c..d9b1c6b 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,14 @@ module github.com/jotadrilo/rubbi-sh go 1.12 require ( + github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect github.com/cesanta/errors v0.0.0-20160612174407-5adec772d663 // indirect github.com/juju/errors v0.0.0-20190207033735-e65537c515d7 github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8 // indirect github.com/juju/testing v0.0.0-20190613124551-e81189438503 // indirect - github.com/kr/pretty v0.1.0 // indirect - github.com/mmikulicic/multierror v0.0.0-20170428094957-c1ad6b5ecd26 - gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect + github.com/manifoldco/promptui v0.3.2 + github.com/mmikulicic/multierror v0.0.0-20170428094957-c1ad6b5ecd26 // indirect + gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c // indirect gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect gopkg.in/yaml.v2 v2.2.2 // indirect ) diff --git a/go.sum b/go.sum index 875b5fd..e67031e 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,24 @@ +github.com/alecthomas/gometalinter v2.0.11+incompatible h1:ENdXMllZNSVDTJUUVIzBW9CSEpntTrQa76iRsEFLX/M= +github.com/alecthomas/gometalinter v2.0.11+incompatible/go.mod h1:qfIpQGGz3d+NmgyPBqv+LSh50emm1pt72EtcX2vKYQk= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/cesanta/errors v0.0.0-20160612174407-5adec772d663 h1:yxe0VAaLkwh7cXoC9IhNhUuJa91au1BMEOWWKxgjK94= github.com/cesanta/errors v0.0.0-20160612174407-5adec772d663/go.mod h1:5V6uYRtJZjiJla602WCKuuB+JiHZDG1E3KOHWmBxr48= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3 h1:I4BOK3PBMjhWfQM2zPJKK7lOBGsrsvOB7kBELP33hiE= +github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= +github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmIpZJGRgNFg2ioYPvFaUxdqpDsg= +github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE= +github.com/gordonklaus/ineffassign v0.0.0-20180909121442-1003c8bd00dc h1:cJlkeAx1QYgO5N80aF5xRGstVsRQwgLR7uA2FnP1ZjY= +github.com/gordonklaus/ineffassign v0.0.0-20180909121442-1003c8bd00dc/go.mod h1:cuNKsD1zp2v6XfE/orVX2QE1LC+i254ceGcVeDT3pTU= +github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU2QjDaorUexogfaMgbipgYATUMU= +github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= github.com/juju/errors v0.0.0-20190207033735-e65537c515d7 h1:dMIPRDg6gi7CUp0Kj2+HxqJ5kTr1iAdzsXYIrLCNSmU= github.com/juju/errors v0.0.0-20190207033735-e65537c515d7/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8 h1:UUHMLvzt/31azWTN/ifGWef4WUqvXk0iRqdhdy/2uzI= @@ -11,8 +30,29 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a h1:weJVJJRzAJBFRlAiJQROKQs8oC9vOxvm4rZmBBk0ONw= +github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= +github.com/manifoldco/promptui v0.3.2 h1:rir7oByTERac6jhpHUPErHuopoRDvO3jxS+FdadEns8= +github.com/manifoldco/promptui v0.3.2/go.mod h1:8JU+igZ+eeiiRku4T5BjtKh2ms8sziGpSYl1gN8Bazw= +github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mmikulicic/multierror v0.0.0-20170428094957-c1ad6b5ecd26 h1:Sk/rGhRF3TAxGR8Ldp3lAUw8GJehJct+5LVU79F13DI= github.com/mmikulicic/multierror v0.0.0-20170428094957-c1ad6b5ecd26/go.mod h1:GNJ15ZAuaQsmIEb/VWpp0pn83vYzb6PglASRGNhEPww= +github.com/nicksnyder/go-i18n v2.0.2+incompatible h1:Xt6dluut3s2zBUha8/3sj6atWMQbFioi9OMqUGH9khg= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9 h1:vY5WqiEon0ZSTGM3ayVVi+twaHKHDFUVloaQ/wug9/c= +github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9/go.mod h1:q+QjxYvZ+fpjMXqs+XEriussHjSYqeXVnAdSV1tkMYk= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3 h1:x/bBzNauLQAlE3fLku/xy92Y8QwKX5HZymrMz2IiKFc= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b h1:MQE+LT/ABUuuvEZ+YQAMSXindAdUh7slEmAkup74op4= +golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/tools v0.0.0-20181122213734-04b5d21e00f1 h1:bsEj/LXbv3BCtkp/rBj9Wi/0Nde4OMaraIZpndHAhdI= +golang.org/x/tools v0.0.0-20181122213734-04b5d21e00f1/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c h1:vTxShRUnK60yd8DZU+f95p1zSLj814+5CuEh7NjF2/Y= +gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c/go.mod h1:3HH7i1SgMqlzxCcBmUHW657sD4Kvv9sC3HpL3YukzwA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/main.go b/main.go index 8f3ecb6..aabaa7e 100644 --- a/main.go +++ b/main.go @@ -16,12 +16,12 @@ var ( date = "unknown" clean = flag.Bool("clean", false, "if true, the rubbish folder is removed") + sel = flag.Bool("sel", false, "if true, prompts the folders list and outputs the choosen one") show = flag.Bool("show", false, "if true, outputs the current rubbish folders") ver = flag.Bool("ver", false, "if true, the rubbish version will be shown") add = flag.String("add", "", "folder name to add") del = flag.String("del", "", "folder number to delete") root = flag.String("root", "/tmp", "temporary location for the rubbish folder") - use = flag.String("use", "", "folder number to use") ) func init() { @@ -69,10 +69,10 @@ func run() error { return nil } - if *use != "" { - fn, err := strconv.Atoi(*use) + if *sel { + fn, err := SelectFolder(config) if err != nil { - return errors.Errorf("failed to parse folder number to use: %+v", err) + return err } if err := config.Use(fn); err != nil { return err diff --git a/tui.go b/tui.go new file mode 100644 index 0000000..9a8957f --- /dev/null +++ b/tui.go @@ -0,0 +1,28 @@ +package main + +import ( + "github.com/juju/errors" + "github.com/manifoldco/promptui" +) + +// SelectFolder prompts a selection menu and returns the choosen folder number +func SelectFolder(config *Config) (int, error) { + folders := make(map[string]int) + items := make([]string, 0, len(folders)) + + for fn, folder := range config.Folders { + folders[folder.Path] = fn + items = append(items, folder.Path) + } + + prompt := promptui.Select{ + Label: "Select Folder", + Items: items, + } + + _, fn, err := prompt.Run() + if err != nil { + return -1, errors.Errorf("failed to prompt folders selection menu: %+v", err) + } + return folders[fn], nil +}