pick 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +27 -17
- data/bin/pick +1 -3
- data/lib/pick/cli.rb +35 -2
- data/lib/pick/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f578b9b265c6232d57211cfd3d1ef6e5d2c64c7
|
4
|
+
data.tar.gz: 1a937ad868bc21e1301045a7b5402c479cec8775
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a43261d19f398144a37004f0cdadacbe35d4786f46990c7ba57ac0c3b25da1ec6f119025e66acfad770609dd4217d722cf895b6860d85ee4b9378cdb048f1fc
|
7
|
+
data.tar.gz: 657b693f29cf2e8067c26b4963464eb0490233b299905c187243006782aa6740387fea1a030ae0945c25e07e2d0fc8f9043d555180d5223845c402cd2713ea9f
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,41 +1,51 @@
|
|
1
1
|
# Pick
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
Pick is a command line tool for selecting from multiple options. It takes items
|
4
|
+
on standard input or from a file, and interactively prompts you to choose one
|
5
|
+
or more of them.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'pick'
|
9
|
+
```sh
|
10
|
+
gem install pick
|
13
11
|
```
|
14
12
|
|
15
|
-
|
13
|
+
## Examples
|
14
|
+
|
15
|
+
```sh
|
16
|
+
# select a file
|
17
|
+
ls | pick
|
16
18
|
|
17
|
-
|
19
|
+
# edit a file under the current directory tree
|
20
|
+
vim $(find . -type f | pick)
|
18
21
|
|
19
|
-
|
22
|
+
# edit multiple files under the current directory tree
|
23
|
+
vim $(find . -type f | pick -m)
|
20
24
|
|
21
|
-
|
25
|
+
# check out a branch interactively
|
26
|
+
git branch -a | pick | xargs git checkout
|
22
27
|
|
23
|
-
|
28
|
+
# delete a file, safe even when filenames contain newlines
|
29
|
+
find . -type f -print0 | pick -0 | xargs -0 rm -v
|
24
30
|
|
25
|
-
|
31
|
+
# delete many files
|
32
|
+
find . -type f -print0 | pick -0 -m | xargs -0 rm -v
|
33
|
+
|
34
|
+
# choose a color from colors.txt
|
35
|
+
pick colors.txt
|
36
|
+
```
|
26
37
|
|
27
38
|
## Development
|
28
39
|
|
29
|
-
After checking out the repo, run `
|
40
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake test` to run the tests. You can use `pry -r ./lib/pick` to get an interactive shell.
|
30
41
|
|
31
42
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
43
|
|
33
44
|
## Contributing
|
34
45
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
36
|
-
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ab/pick/.
|
37
47
|
|
38
48
|
## License
|
39
49
|
|
40
|
-
The gem is available as open source under the terms of the [
|
50
|
+
The gem is available as open source under the terms of the [GPL v3](https://opensource.org/licenses/GPL-3.0).
|
41
51
|
|
data/bin/pick
CHANGED
data/lib/pick/cli.rb
CHANGED
@@ -3,17 +3,48 @@ require 'tty/screen'
|
|
3
3
|
|
4
4
|
module Pick
|
5
5
|
class CLI
|
6
|
+
|
7
|
+
# Read items from input_io and prompt the user to choose among them. Then
|
8
|
+
# print the output to options[:output_io] or stdout.
|
9
|
+
#
|
10
|
+
# @param input_io [IO] The input IO from which to read the items
|
11
|
+
# @param options [Hash] See {.prompt}
|
12
|
+
# @option options :output_io [IO] (STDOUT) The IO to print selected items
|
13
|
+
# to.
|
14
|
+
# @option options :output_delimiter [String] ("\n") The delimiter to print
|
15
|
+
# after each selected item.
|
16
|
+
#
|
6
17
|
def self.run(input_io, options={})
|
7
18
|
answer = prompt(input_io, options)
|
8
19
|
|
20
|
+
return if answer.empty?
|
21
|
+
|
9
22
|
output_io = options[:output_io] || STDOUT
|
10
23
|
|
11
24
|
out_sep = options[:output_delimiter]
|
12
25
|
out_sep ||= "\n"
|
13
26
|
|
14
27
|
output_io.print(Array(answer).join(out_sep) + out_sep)
|
28
|
+
|
29
|
+
answer
|
15
30
|
end
|
16
31
|
|
32
|
+
# Read items from input_io and prompt the user to choose among them.
|
33
|
+
#
|
34
|
+
# @param input_io [IO] The input IO from which to read the items
|
35
|
+
# @param options [Hash]
|
36
|
+
# @option options :prompt_input [IO] IO to use for prompt input
|
37
|
+
# @option options :prompt_output [IO] IO to use for prompt output
|
38
|
+
# @option options :tty_dev [String] ('/dev/tty') The device to use as the
|
39
|
+
# default for TTY i/o, used for :prompt_input and :prompt_output
|
40
|
+
# @option options :input_delimiter [String] The string that separates items
|
41
|
+
# on the input stream.
|
42
|
+
# @option options :multiple [Boolean] Whether to select a single item or
|
43
|
+
# multiple items
|
44
|
+
#
|
45
|
+
# @return [String, Array<String>] A single item or an array of items chosen
|
46
|
+
# by the user.
|
47
|
+
#
|
17
48
|
def self.prompt(input_io, options={})
|
18
49
|
prompt_opts = {}
|
19
50
|
options = options.dup
|
@@ -28,6 +59,10 @@ module Pick
|
|
28
59
|
prompt_opts[:per_page] = options.fetch(:per_page)
|
29
60
|
end
|
30
61
|
|
62
|
+
if input_io.tty? && options.fetch(:prompt_output).tty? \
|
63
|
+
&& !options[:quiet]
|
64
|
+
options.fetch(:prompt_output).puts('Waiting for input items...')
|
65
|
+
end
|
31
66
|
|
32
67
|
# read the input io
|
33
68
|
data = input_io.read
|
@@ -42,8 +77,6 @@ module Pick
|
|
42
77
|
# split input into choices
|
43
78
|
choices = data.split(separator)
|
44
79
|
|
45
|
-
prompt = options.fetch(:prompt, 'Pick an option:')
|
46
|
-
|
47
80
|
p = TTY::Prompt.new(
|
48
81
|
input: options.fetch(:prompt_input),
|
49
82
|
output: options.fetch(:prompt_output)
|
data/lib/pick/version.rb
CHANGED