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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 231a0858bec544792385a82e9111bdb7debc6860
4
- data.tar.gz: 3178c3fb7fd85d4a5e0630e1df1fcb004d7fa08a
3
+ metadata.gz: 1f578b9b265c6232d57211cfd3d1ef6e5d2c64c7
4
+ data.tar.gz: 1a937ad868bc21e1301045a7b5402c479cec8775
5
5
  SHA512:
6
- metadata.gz: ff367787f4196c730c831eea89878df45c1f70091ac4725fb730522e45b8095e4a233214406c64067c570af6dec8f0164bbb01d1162baa6cd4cc6f13e10cc1af
7
- data.tar.gz: 026d6830026c67daca200dc0f59934bc2c8dbf6c3244b88d83310547abc3222747e63c27acc99f22afcb6ce52a55343762270d9188fef04dc7bc3318b076732f
6
+ metadata.gz: 5a43261d19f398144a37004f0cdadacbe35d4786f46990c7ba57ac0c3b25da1ec6f119025e66acfad770609dd4217d722cf895b6860d85ee4b9378cdb048f1fc
7
+ data.tar.gz: 657b693f29cf2e8067c26b4963464eb0490233b299905c187243006782aa6740387fea1a030ae0945c25e07e2d0fc8f9043d555180d5223845c402cd2713ea9f
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Andy Brody
1
+ Copyright (c) 2017 Andy Brody
2
2
 
3
3
  GNU GENERAL PUBLIC LICENSE
4
4
  Version 3, 29 June 2007
data/README.md CHANGED
@@ -1,41 +1,51 @@
1
1
  # Pick
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pick`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
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
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'pick'
9
+ ```sh
10
+ gem install pick
13
11
  ```
14
12
 
15
- And then execute:
13
+ ## Examples
14
+
15
+ ```sh
16
+ # select a file
17
+ ls | pick
16
18
 
17
- $ bundle
19
+ # edit a file under the current directory tree
20
+ vim $(find . -type f | pick)
18
21
 
19
- Or install it yourself as:
22
+ # edit multiple files under the current directory tree
23
+ vim $(find . -type f | pick -m)
20
24
 
21
- $ gem install pick
25
+ # check out a branch interactively
26
+ git branch -a | pick | xargs git checkout
22
27
 
23
- ## Usage
28
+ # delete a file, safe even when filenames contain newlines
29
+ find . -type f -print0 | pick -0 | xargs -0 rm -v
24
30
 
25
- TODO: Write usage instructions here
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 `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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/[USERNAME]/pick.
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 [MIT License](http://opensource.org/licenses/MIT).
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
@@ -94,6 +94,4 @@ Options:
94
94
  end
95
95
  end
96
96
 
97
- if $0 == __FILE__
98
- main(ARGV)
99
- end
97
+ main(ARGV)
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
@@ -1,3 +1,3 @@
1
1
  module Pick
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Brody