Skip to content

Commit

Permalink
Add terminal interface and 'sel' option
Browse files Browse the repository at this point in the history
  • Loading branch information
jotadrilo committed Jun 25, 2019
1 parent c208d31 commit ece4629
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 15 deletions.
3 changes: 2 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
## 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)

- Fix alias not to depend on others

## Release 0.0.12 (2019-06-15)

- Fix Hombrew formula
- Fix **Hombrew** formula
- Fix alias files

## Release 0.0.11 (2019-06-15)
Expand Down
6 changes: 1 addition & 5 deletions dotfiles/.rubbi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
40 changes: 40 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions tui.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit ece4629

Please sign in to comment.