telepath 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e69b7082bfdff850dd491c0b7afbd3f37eb611d
4
- data.tar.gz: 9dcc58cf0842de030bba29f97a399df0a2c54387
3
+ metadata.gz: b38bc8a0619f00d35224b7e2586a0d193074f7a3
4
+ data.tar.gz: 81772bf8131f737c3071e2566158559f576edaa7
5
5
  SHA512:
6
- metadata.gz: c756e27d743378158c557de22d20d2e64f8795bfe7a0013e5cf1eba0a3725b96f9ce7fac9c7d137d7046104147a8298e021387ee49149e5b010f41a21867a34e
7
- data.tar.gz: 4a0c542a0f0190460e30125579e24eda0f843b4a8813cbf9c78f2dbc4fab940bf66d5f085f566e6353a7e812b3ba6a6d732988729afe6430c73194b1efac4599
6
+ metadata.gz: a32bab376cf4b20156be53dceb4c5e567a103f4dc4174664dc16a99d746eabd8582cbb34329266d7eb79444c231205629071b501b1556ebff4a98258b340f07a
7
+ data.tar.gz: 16b7370de869fc20fb802bdea9ca45516c1ddb0b70dd8d947b9a2ef2fd522c68bca4eb252771afe5096bab41fb08a2d0811ee65ba4e3fb5edc2dab06d28e4ea6
data/README.markdown CHANGED
@@ -3,6 +3,7 @@ Telepath
3
3
 
4
4
  Spooky action at a distance.
5
5
 
6
+ [![Gem Version](https://badge.fury.io/rb/telepath.png)](http://badge.fury.io/rb/telepath)
6
7
  [![Build Status](https://travis-ci.org/acook/telepath.png?branch=master)](https://travis-ci.org/acook/telepath)
7
8
  [![Code Climate](https://codeclimate.com/github/acook/telepath.png)](https://codeclimate.com/github/acook/telepath)
8
9
  [![Dependency Status](https://gemnasium.com/acook/telepath.png)](https://gemnasium.com/acook/telepath)
@@ -33,6 +34,80 @@ What about shared, persistant, distributed, fully decorated multi-client multi-h
33
34
  Yeah thats pretty much what I thought. Now go change your pants, I'll still be here when you get back.
34
35
 
35
36
 
37
+ Installation & Setup
38
+ --------------------
39
+
40
+ ### Install it!
41
+
42
+ ```sh
43
+ gem install telepath
44
+ ```
45
+
46
+ ### Set it up!
47
+
48
+ Actually, thats pretty much it. Telepath just works.
49
+
50
+
51
+ Usage
52
+ -----
53
+
54
+ Here's the output of `tel --help`:
55
+
56
+ ```sh
57
+ Usage:
58
+ tel [OPTIONS] SUBCOMMAND [ARG] ...
59
+
60
+ Parameters:
61
+ SUBCOMMAND subcommand
62
+ [ARG] ... subcommand arguments
63
+
64
+ Subcommands:
65
+ +, add Add item
66
+ ?, lookup Look up item by pattern
67
+ $, last Get most recent item
68
+ @, index Get item from (reverse) index
69
+
70
+ Options:
71
+ -q, --quiet Only output when absolutely necessary. (default: $TELEPORT_QUIET, or false)
72
+ -f, --file FILE Filename of the Teleport store file. (default: $TELEPORT_FILE, or ".telepath.db")
73
+ -p, --path PATH Path where the the Teleport store file is located. (default: $TELEPORT_PATH, or "~")
74
+ -h, --help print help
75
+ ```
76
+
77
+ Example
78
+ -------
79
+
80
+ Dump data into Telepath from Bash...
81
+
82
+ ```bash
83
+ $ tel + "All the things!"
84
+ ```
85
+
86
+ Use it in Vim...
87
+
88
+ ```viml
89
+ :r ! tel $
90
+ ```
91
+
92
+ Use it again in Zsh...
93
+
94
+ ```zsh
95
+ ∴ export which_things=$(tel $)
96
+ ```
97
+
98
+ Manipulate it with `tr` in zsh and add the result back into Telepath...
99
+
100
+ ```zsh
101
+ ∴ tel $ | tr '[:lower:]' '[:upper:]' | tel +
102
+ ```
103
+
104
+ And bring it back into Bash to combine it with the previous version...
105
+
106
+ ```bash
107
+ $ echo $(tel $) $(tel @ 1) | tee result.txt | tel +
108
+ ```
109
+
110
+
36
111
  Contributing
37
112
  ------------
38
113
 
@@ -50,4 +125,6 @@ I'm glad you asked!
50
125
 
51
126
  Anthony M. Cook 2013
52
127
 
128
+ Inspired by this perl script: [oknowton/shstack](https://github.com/oknowton/shstack)
129
+
53
130
 
@@ -3,29 +3,51 @@ require 'clamp'
3
3
  module Telepath
4
4
  class Command < ::Clamp::Command
5
5
 
6
- option ['-q', '--quiet'], :flag, "Only output when absolutely necessary."
6
+ option ['-q', '--quiet'], :flag, 'Only output when absolutely necessary.',
7
+ environment_variable: 'TELEPORT_QUIET', default: false
7
8
 
8
- subcommand ['+'], 'Add item to Telepath' do
9
- parameter 'VALUE', 'value to add'
9
+ option ['-f', '--file'], 'FILE', 'Filename of the Teleport store file.',
10
+ environment_variable: 'TELEPORT_FILE', default: Telepath::Storage::DEFAULT_FILE
11
+
12
+ option ['-p', '--path'], 'PATH', 'Path where the the Teleport store file is located.',
13
+ environment_variable: 'TELEPORT_PATH', default: Telepath::Storage::DEFAULT_PATH
14
+
15
+ subcommand ['+', 'add'], 'Add item' do
16
+ parameter '[VALUE] ...', 'value to add', attribute_name: 'values'
10
17
 
11
18
  def execute
12
19
  handler = Telepath::Handler.new self
13
- success, name = handler.add value
20
+ values = self.values || Array.new
21
+
22
+ unless $stdin.tty? then
23
+ buffered = IO.select([$stdin], [], [], 1)
24
+ values << $stdin.read.strip if buffered && buffered.first && buffered.first.first
25
+ end
26
+
27
+ Out.error self, "No values supplied!" if values.empty?
28
+
29
+ results = values.map do |value|
30
+ handler.add value
31
+ end
32
+
33
+ success = results.all?{|r|r.first}
34
+ name = results.first.last
14
35
 
15
36
  if success then
16
- Out.info "Added `#{value}' to `#{name}'!"
37
+ Out.info "Added [#{values.map(&:inspect).join ', '}] to `#{name}'!"
17
38
  else
18
- Out.error self, "Could not add `#{value}' to `#{name}'!"
39
+ failures = values.reject.with_index{|_, i| results[i].first}
40
+ Out.error self, "Could not add [#{failures.map().join ', '}] to `#{name}'!"
19
41
  end
20
42
  end
21
43
  end
22
44
 
23
- subcommand ['='], 'Grab item from Telepath' do
45
+ subcommand ['?', 'lookup'], 'Look up item by pattern' do
24
46
  parameter '[PATTERN]', 'pattern to find'
25
47
 
26
48
  def execute
27
49
  handler = Telepath::Handler.new self
28
- value = handler.grab pattern
50
+ value = handler.lookup pattern
29
51
 
30
52
  if value && !value.empty? then
31
53
  Out.data value
@@ -35,6 +57,38 @@ module Telepath
35
57
  end
36
58
  end
37
59
 
60
+ subcommand ['$', 'last'], 'Get most recent item' do
61
+ def execute
62
+ handler = Telepath::Handler.new self
63
+ value = handler.last
64
+
65
+ if value && !value.empty? then
66
+ Out.data value
67
+ else
68
+ Out.error self, "Telepath is empty, is your storage location configured properly?"
69
+ end
70
+ end
71
+ end
72
+
73
+ subcommand ['@', 'index'], 'Get item from (reverse) index' do
74
+ parameter 'INDEX ...', 'index of item, starting from most recent (0)',
75
+ attribute_name: :indicies do |i|
76
+ Integer(i)
77
+ end
78
+
79
+ def execute
80
+ handler = Telepath::Handler.new self
81
+ index = indicies.first
82
+ value = handler.index index
83
+
84
+ if value && !value.to_s.empty? then
85
+ Out.data value
86
+ else
87
+ Out.error self, "Hmm, couldn't find anything at that index."
88
+ end
89
+ end
90
+ end
91
+
38
92
  def execute
39
93
  exit 1
40
94
  end
@@ -14,7 +14,13 @@ module Telepath
14
14
  [true, name]
15
15
  end
16
16
 
17
- def grab pattern = nil
17
+ def last
18
+ with_store 'stack' do |container|
19
+ container.last
20
+ end
21
+ end
22
+
23
+ def lookup pattern
18
24
  with_store 'stack' do |container|
19
25
 
20
26
  if pattern && !pattern.empty? then
@@ -32,6 +38,14 @@ module Telepath
32
38
  end
33
39
  end
34
40
 
41
+ def index *indicies
42
+ index = indicies.first
43
+
44
+ with_store 'stack' do |container|
45
+ container[-(index.to_i + 1)]
46
+ end
47
+ end
48
+
35
49
  def storage
36
50
  if @storage && @storage.ready? then
37
51
  @storage
@@ -1,3 +1,3 @@
1
1
  module Telepath
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/spec/exe_spec.rb CHANGED
@@ -26,7 +26,7 @@ describe 'Telepath Executable' do
26
26
  specify { expect(status).to_not be_success }
27
27
  end
28
28
 
29
- describe '+' do
29
+ describe '+ add' do
30
30
  let(:command){ :+ }
31
31
 
32
32
  context 'without value' do
@@ -39,13 +39,17 @@ describe 'Telepath Executable' do
39
39
  specify { expect(status).to be_success }
40
40
 
41
41
  it 'adds the value to the stack' do
42
- expect(stdout).to eq("Added `12' to `stack'!")
42
+ expect(stdout).to eq("Added [\"12\"] to `stack'!")
43
+ end
44
+
45
+ it 'should have no error output' do
46
+ expect(exe.stderr).to eq ''
43
47
  end
44
48
  end
45
49
  end
46
50
 
47
- describe '=' do
48
- let(:command){ '=' }
51
+ describe '? lookup' do
52
+ let(:command){ '?' }
49
53
  let(:handler){ Telepath::Handler.new double(Clamp::Command) }
50
54
  let(:value){ '12' }
51
55
 
data/spec/handler_spec.rb CHANGED
@@ -7,6 +7,11 @@ describe Telepath::Handler do
7
7
  subject(:handler){ described_class.new double(Clamp::Command) }
8
8
 
9
9
  let(:storage){ Telepath::Storage.new }
10
+ let(:value){ 'whatever' }
11
+
12
+ before do
13
+ handler.add value
14
+ end
10
15
 
11
16
  it 'exists' do
12
17
  expect(described_class).to be
@@ -18,30 +23,60 @@ describe Telepath::Handler do
18
23
 
19
24
  describe '#add' do
20
25
  it 'adds 1 item' do
21
- expect{ handler.add 'whatever' }.to change{
26
+ expect{ handler.add 'something' }.to change{
22
27
  storage.store.adapter.backend.sunrise
23
28
  storage.stack.length
24
- }.from(0).to(1)
29
+ }.from(1).to(2)
25
30
  end
26
31
 
27
32
  it 'adds the right item' do
28
- handler.add 'whatever'
29
- expect(storage.stack).to include('whatever')
33
+ handler.add 'something'
34
+ expect(storage.stack).to include('something')
35
+ end
36
+
37
+ context 'redirected input' do
38
+ xit 'reads and stores stdin' do
39
+ end
30
40
  end
31
41
  end
32
42
 
33
- describe '#grab' do
34
- let(:value){ 'whatever' }
43
+ describe '#last' do
44
+ it 'returns the last value' do
45
+ expect(handler.last).to eq(value)
46
+ end
47
+
48
+ it 'does not delete the item' do
49
+ expect{ handler.last }.to change{
50
+ storage.store.adapter.backend.sunrise
51
+ storage.stack.length
52
+ }.by(0)
53
+ end
54
+ end
55
+
56
+ describe '#index' do
35
57
  before do
36
- handler.add value
58
+ handler.add 'blah'
59
+ end
60
+
61
+ it 'returns the item at the specified reverse index (1)' do
62
+ expect(handler.index 1).to eq(value)
37
63
  end
38
64
 
39
- it 'grabs last value' do
40
- expect(handler.grab).to eq(value)
65
+ it 'returns the item at the specified reverse index (0)' do
66
+ expect(handler.index 0).to eq('blah')
41
67
  end
42
68
 
43
69
  it 'does not delete the item' do
44
- expect{ handler.grab value }.to change{
70
+ expect{ handler.index value }.to change{
71
+ storage.store.adapter.backend.sunrise
72
+ storage.stack.length
73
+ }.by(0)
74
+ end
75
+ end
76
+
77
+ describe '#lookup' do
78
+ it 'does not delete the item' do
79
+ expect{ handler.lookup value }.to change{
45
80
  storage.store.adapter.backend.sunrise
46
81
  storage.stack.length
47
82
  }.by(0)
@@ -49,14 +84,14 @@ describe Telepath::Handler do
49
84
 
50
85
  context 'pattern matching' do
51
86
  it 'matches substrings of words' do
52
- expect(handler.grab('what')).to eq(value)
87
+ expect(handler.lookup('what')).to eq(value)
53
88
  end
54
89
 
55
90
  context 'numbers' do
56
91
  let(:value){ '12' }
57
92
 
58
93
  it 'matches parts of numbers' do
59
- expect(handler.grab('1')).to eq(value)
94
+ expect(handler.lookup('1')).to eq(value)
60
95
  end
61
96
  end
62
97
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telepath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Cook