peanut 0.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.
- data/README.rdoc +22 -0
- data/bin/peanut +7 -0
- data/lib/peanut/clipboard.rb +24 -0
- data/lib/peanut/command.rb +75 -0
- data/lib/peanut/store.rb +47 -0
- data/lib/peanut/version.rb +3 -0
- data/lib/peanut.rb +10 -0
- data/peanut.gemspec +21 -0
- data/test/examples/test.json +1 -0
- data/test/helper.rb +20 -0
- data/test/test_command.rb +31 -0
- metadata +93 -0
data/README.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
= Peanut
|
2
|
+
|
3
|
+
Peanut is a key/value store kind of similar to BOOM. Instead of managing lists, we store everything in 1 key value store to keep things simple.
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
Usage is pretty straight forward:
|
8
|
+
|
9
|
+
peanut help show a quick help overview
|
10
|
+
peanut <key> <value> adds the key/value pair to your bucket
|
11
|
+
peanut rm <key> removes the key/value pair where key matches
|
12
|
+
peanut <key> copies the value of key to your clipboard
|
13
|
+
peanut <key> v adds the value of your clipboard to key
|
14
|
+
peanut list shows everything currently in your bucket
|
15
|
+
|
16
|
+
== Installation
|
17
|
+
|
18
|
+
gem install zap
|
19
|
+
|
20
|
+
== Requirements
|
21
|
+
|
22
|
+
Peanut should function on Linux, BSD (assuming you run X), or Mac OS X. There are currently a few bugs on some Linux systems I've tested. xclip seems to hang, although it actually functions. I'm working on that!
|
data/bin/peanut
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Peanut
|
2
|
+
class Clipboard
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def copy(string)
|
6
|
+
cmd = if RUBY_PLATFORM =~ /linux/
|
7
|
+
"xclip -selection clipboard"
|
8
|
+
else
|
9
|
+
"pbcopy"
|
10
|
+
end
|
11
|
+
|
12
|
+
`echo #{string} | tr -d "\n" | #{cmd}`
|
13
|
+
end
|
14
|
+
|
15
|
+
def paste
|
16
|
+
if RUBY_PLATFORM =~ /linux/
|
17
|
+
`xclip -selection clipboard -o`
|
18
|
+
else
|
19
|
+
`pbpaste`
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Peanut
|
2
|
+
class Command
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def run(*args)
|
6
|
+
key = args.shift
|
7
|
+
value = args.join(' ') unless args.length == 0
|
8
|
+
|
9
|
+
return help unless key
|
10
|
+
return send key, value if is_arged_keyword?(key)
|
11
|
+
return send key if is_keyword?(key)
|
12
|
+
return save key, value if key && value
|
13
|
+
return get key
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def store
|
19
|
+
@store ||= Peanut::Store.new(ENV['HOME'] + '/.peanut')
|
20
|
+
end
|
21
|
+
|
22
|
+
def list
|
23
|
+
puts "Your peanut bucket: \n#{'-' * 20}"
|
24
|
+
store.each_pair do |key, value|
|
25
|
+
puts "#{key}: #{value}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def help
|
30
|
+
puts %{
|
31
|
+
#{executable} <key> <value> sets the "key" value to "value"
|
32
|
+
#{executable} <key> copies the value for "key" to the clipboard
|
33
|
+
#{executable} rm <foo> removes the key/value pair where the key = foo
|
34
|
+
#{executable} <foo> v stores your current clipboard value into foo
|
35
|
+
#{executable} list shows all the values that are in your peanut bucket
|
36
|
+
#{executable} help shows you this help document
|
37
|
+
}.gsub(/^ {10}/, '') # murderous villain of whitespace
|
38
|
+
end
|
39
|
+
|
40
|
+
def get(key)
|
41
|
+
if val = store[key]
|
42
|
+
Clipboard.copy(val)
|
43
|
+
puts "Copied '#{val}' to the clipboard!"
|
44
|
+
else
|
45
|
+
puts "No value stored with key '#{key}'"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def save(key, val)
|
50
|
+
val = Clipboard.paste if val == 'v'
|
51
|
+
store[key.intern] = val
|
52
|
+
store.save
|
53
|
+
puts "Saved '#{val}' as '#{key}'"
|
54
|
+
end
|
55
|
+
|
56
|
+
def executable
|
57
|
+
@executable ||= $0.split('/').pop
|
58
|
+
end
|
59
|
+
|
60
|
+
def rm(key)
|
61
|
+
store[key] = nil
|
62
|
+
store.save
|
63
|
+
puts "Deleted the value with the key '#{key}'"
|
64
|
+
end
|
65
|
+
|
66
|
+
def is_keyword?(word)
|
67
|
+
['rm', 'list', 'help'].include? word
|
68
|
+
end
|
69
|
+
|
70
|
+
def is_arged_keyword?(word)
|
71
|
+
['rm'].include? word
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/peanut/store.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Peanut
|
2
|
+
class Store
|
3
|
+
|
4
|
+
attr_accessor :store, :file
|
5
|
+
|
6
|
+
def initialize(file)
|
7
|
+
self.file = file
|
8
|
+
|
9
|
+
init_file unless File.exists?(file)
|
10
|
+
self.store = Yajl::Parser.parse(File.new(file, 'r'))
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_json
|
14
|
+
Yajl::Encoder.encode(store)
|
15
|
+
end
|
16
|
+
|
17
|
+
def []=(key, val)
|
18
|
+
self.store[key] = val
|
19
|
+
self.store.delete(key) if val.nil?
|
20
|
+
return val
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](key)
|
24
|
+
return store[key]
|
25
|
+
end
|
26
|
+
|
27
|
+
def save
|
28
|
+
File.open(file, 'w') { |f| f.write(to_json) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def each_pair
|
32
|
+
store.each do |key, val|
|
33
|
+
yield key, val
|
34
|
+
end
|
35
|
+
|
36
|
+
if store.empty?
|
37
|
+
yield "Bucket", "empty"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def init_file
|
44
|
+
File.open(file, 'w') { |f| f.write "{}" }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/peanut.rb
ADDED
data/peanut.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path("../lib/peanut/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "peanut"
|
5
|
+
s.version = Peanut::VERSION
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.authors = ['the_gastropod', 'chrisrhoden']
|
8
|
+
s.email = []
|
9
|
+
s.homepage = "http://rubygems.org/gems/peanut"
|
10
|
+
s.summary = "Peanut is a friendly remake of BOOM, where we manage simple key/value stores instead of lists."
|
11
|
+
s.description = "Peanut is a simple command line clipboard manager similar to BOOM. We use key/value stores instead of lists, keeping things simple."
|
12
|
+
|
13
|
+
s.required_rubygems_version = ">= 1.3.6"
|
14
|
+
s.rubyforge_project = "peanut"
|
15
|
+
|
16
|
+
s.add_dependency 'yajl-ruby'
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
20
|
+
s.require_path = 'lib'
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"keya":"this is value a","keyb":"this is value b"}
|
data/test/helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
require 'redgreen' # We'd like to see pretty pass/fails!
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'mocha'
|
10
|
+
|
11
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
|
14
|
+
require 'peanut'
|
15
|
+
|
16
|
+
def peanut_json(name)
|
17
|
+
#Peanut::Store.any_instance.stubs(:json_file).
|
18
|
+
#returns("test/examples/#{name}.json")
|
19
|
+
Peanut.stubs(:storage).returns(Peanut::Store.new("examples/#{name}.json"))
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
# Dont Mind this
|
4
|
+
# Just a little ghetto monkey patching
|
5
|
+
# It lets us grab the STD I/O, and test it
|
6
|
+
class Object
|
7
|
+
class << self
|
8
|
+
attr_accessor :output
|
9
|
+
def puts(s)
|
10
|
+
@output = s
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class TestCommand < Test::Unit::TestCase
|
16
|
+
|
17
|
+
def setup
|
18
|
+
peanut_json "test"
|
19
|
+
end
|
20
|
+
|
21
|
+
def command(cmd)
|
22
|
+
cmd = cmd.split(' ') if cmd
|
23
|
+
Object.puts Peanut::Command.run(*cmd)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_adding_entry
|
27
|
+
assert_equal "Saved 'testing' as 'test'", command("test testing")
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: peanut
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- the_gastropod
|
13
|
+
- chrisrhoden
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-11 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: yajl-ruby
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Peanut is a simple command line clipboard manager similar to BOOM. We use key/value stores instead of lists, keeping things simple.
|
36
|
+
email: []
|
37
|
+
|
38
|
+
executables:
|
39
|
+
- peanut
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- README.rdoc
|
46
|
+
- bin/peanut
|
47
|
+
- lib/peanut.rb
|
48
|
+
- lib/peanut/clipboard.rb
|
49
|
+
- lib/peanut/command.rb
|
50
|
+
- lib/peanut/store.rb
|
51
|
+
- lib/peanut/version.rb
|
52
|
+
- peanut.gemspec
|
53
|
+
- test/examples/test.json
|
54
|
+
- test/helper.rb
|
55
|
+
- test/test_command.rb
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://rubygems.org/gems/peanut
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 23
|
80
|
+
segments:
|
81
|
+
- 1
|
82
|
+
- 3
|
83
|
+
- 6
|
84
|
+
version: 1.3.6
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project: peanut
|
88
|
+
rubygems_version: 1.4.2
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Peanut is a friendly remake of BOOM, where we manage simple key/value stores instead of lists.
|
92
|
+
test_files: []
|
93
|
+
|