zap 0.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/.gitignore +3 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +18 -0
- data/README.rdoc +26 -0
- data/Rakefile +2 -0
- data/bin/zap +7 -0
- data/lib/zap.rb +9 -0
- data/lib/zap/clipboard.rb +22 -0
- data/lib/zap/command.rb +82 -0
- data/lib/zap/store.rb +43 -0
- data/lib/zap/version.rb +3 -0
- data/zap.gemspec +24 -0
- metadata +110 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= Peanut
|
2
|
+
|
3
|
+
Peanut is a cheap knockoff of the Boom gem. Instead of managing different lists, Peanut uses a "Bucket" to dump all of your items.
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
I'd recommend using an alias for Peanut. Something like:
|
8
|
+
|
9
|
+
alias peanut="/path/to/your/peanut.rb"
|
10
|
+
|
11
|
+
Assuming such an alias is setup, usage is pretty easy:
|
12
|
+
|
13
|
+
peanut help show a quick help overview
|
14
|
+
peanut add <key> <value> adds the key/value pair to your bucket
|
15
|
+
peanut list shows everything currently in your bucket
|
16
|
+
peanut del <key> removes the key/value pair where key matches
|
17
|
+
peanut get <key> copies the value of key to your clipboard
|
18
|
+
|
19
|
+
== Requirements
|
20
|
+
|
21
|
+
Requires the yajl gem. Install rajl with:
|
22
|
+
|
23
|
+
gem sources -a http://gemcutter.org
|
24
|
+
sudo gem install yajl-ruby
|
25
|
+
|
26
|
+
Peanut should function on Linux, BSD (assuming you run X), or Mac OS X.
|
data/Rakefile
ADDED
data/bin/zap
ADDED
data/lib/zap.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Zap
|
2
|
+
module Clipboard
|
3
|
+
def self.copy(string)
|
4
|
+
|
5
|
+
cmd = if RUBY_PLATFORM =~ /linux/
|
6
|
+
"xclip -selection clipboard"
|
7
|
+
else
|
8
|
+
"pbcopy"
|
9
|
+
end
|
10
|
+
|
11
|
+
`echo #{string} | tr -d "\n" | #{cmd}`
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.paste
|
15
|
+
if RUBY_PLATFORM =~ /darwin/
|
16
|
+
`pbpaste`
|
17
|
+
else
|
18
|
+
`xclip -selection clipboard -o`
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/zap/command.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
module Zap
|
2
|
+
module Command
|
3
|
+
class << self
|
4
|
+
def run(*args)
|
5
|
+
key = args.shift
|
6
|
+
value = args.join(' ') unless args.length == 0
|
7
|
+
|
8
|
+
return help unless key
|
9
|
+
return send key, value if is_arged_keyword?(key)
|
10
|
+
return send key if is_keyword?(key)
|
11
|
+
return save key, value if key && value
|
12
|
+
return get key
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def store
|
18
|
+
@store ||= Zap::Store.new(ENV['HOME'] + '/.zapstore')
|
19
|
+
end
|
20
|
+
|
21
|
+
def list
|
22
|
+
store.each_pair do |key, value|
|
23
|
+
puts "Your zapvals are:", '-'*17
|
24
|
+
puts "#{key}: #{value}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def help
|
29
|
+
puts %{
|
30
|
+
::::::::: :::. ::::::::::. .:
|
31
|
+
'`````;;; ;;`;; `;;;```.;;;;;;
|
32
|
+
.n[[',[[ '[[, `]]nnn]]' '[[
|
33
|
+
,$$P" c$$$cc$$$c $$$"" $$
|
34
|
+
,888bo,_ 888 888,888o ""
|
35
|
+
`""*UMM YMM ""` YMMMb MM
|
36
|
+
#{executable}'s snatchin yo clipboards up.
|
37
|
+
|
38
|
+
`#{executable} foo bar` sets the "foo" value to "bar"
|
39
|
+
`#{executable} foo` copies the contents of "foo" into your clipboard
|
40
|
+
`#{executable} rm foo` unsets the value of "foo"
|
41
|
+
`#{executable} foo p` copies the contents of your clipboard into "foo"
|
42
|
+
`#{executable} list` shows the values zap knows about.
|
43
|
+
`#{executable} help` shows this help.
|
44
|
+
}.gsub(/^ {10}/, '') # murderous villian of whitespace
|
45
|
+
end
|
46
|
+
|
47
|
+
def get(key)
|
48
|
+
if val = store[key]
|
49
|
+
Clipboard.copy(val)
|
50
|
+
puts "Copied \"#{val}\" to the clipboard!"
|
51
|
+
else
|
52
|
+
puts "No value stored with key \"#{key}\""
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def save(key, value)
|
57
|
+
value = Clipboard.paste if value == 'p'
|
58
|
+
store[key.intern] = value
|
59
|
+
store.write
|
60
|
+
puts "Saved \"#{value}\" as \"#{key}\""
|
61
|
+
end
|
62
|
+
|
63
|
+
def executable
|
64
|
+
@executable ||= $0.split('/').pop
|
65
|
+
end
|
66
|
+
|
67
|
+
def rm(key)
|
68
|
+
store[key] = nil
|
69
|
+
store.write
|
70
|
+
puts "Deleted the value with the key \"#{key}\""
|
71
|
+
end
|
72
|
+
|
73
|
+
def is_keyword?(word)
|
74
|
+
['rm', 'list', 'help'].include? word
|
75
|
+
end
|
76
|
+
|
77
|
+
def is_arged_keyword?(word)
|
78
|
+
['rm'].include? word
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/zap/store.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Zap
|
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 write
|
18
|
+
File.open(file, 'w') { |f| f.write(to_json) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def []=(key, value)
|
22
|
+
self.store[key] = value
|
23
|
+
self.store.delete(key) if value.nil?
|
24
|
+
value
|
25
|
+
end
|
26
|
+
|
27
|
+
def [](key)
|
28
|
+
store[key]
|
29
|
+
end
|
30
|
+
|
31
|
+
def each_pair
|
32
|
+
store.each do |(key, value)|
|
33
|
+
yield key, value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def init_file
|
40
|
+
File.open(file, 'w') { |f| f.write "{}" }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/zap/version.rb
ADDED
data/zap.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/zap/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "zap"
|
6
|
+
s.version = Zap::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = []
|
9
|
+
s.email = []
|
10
|
+
s.homepage = "http://rubygems.org/gems/zap"
|
11
|
+
s.summary = "Zap is a simpler BOOM. Plus, it's one character shorter!"
|
12
|
+
s.description = "Zap is a simple command line key-value store. There are no collections, just a single namespace, and only three letters in the command. ZAP!"
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "zap"
|
16
|
+
|
17
|
+
s.add_dependency 'yajl-ruby'
|
18
|
+
|
19
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
23
|
+
s.require_path = 'lib'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors: []
|
13
|
+
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-07 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
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: bundler
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 23
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 0
|
47
|
+
- 0
|
48
|
+
version: 1.0.0
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
description: Zap is a simple command line key-value store. There are no collections, just a single namespace, and only three letters in the command. ZAP!
|
52
|
+
email: []
|
53
|
+
|
54
|
+
executables:
|
55
|
+
- zap
|
56
|
+
extensions: []
|
57
|
+
|
58
|
+
extra_rdoc_files: []
|
59
|
+
|
60
|
+
files:
|
61
|
+
- .gitignore
|
62
|
+
- Gemfile
|
63
|
+
- Gemfile.lock
|
64
|
+
- README.rdoc
|
65
|
+
- Rakefile
|
66
|
+
- bin/zap
|
67
|
+
- lib/zap.rb
|
68
|
+
- lib/zap/clipboard.rb
|
69
|
+
- lib/zap/command.rb
|
70
|
+
- lib/zap/store.rb
|
71
|
+
- lib/zap/version.rb
|
72
|
+
- zap.gemspec
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://rubygems.org/gems/zap
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 23
|
97
|
+
segments:
|
98
|
+
- 1
|
99
|
+
- 3
|
100
|
+
- 6
|
101
|
+
version: 1.3.6
|
102
|
+
requirements: []
|
103
|
+
|
104
|
+
rubyforge_project: zap
|
105
|
+
rubygems_version: 1.4.1
|
106
|
+
signing_key:
|
107
|
+
specification_version: 3
|
108
|
+
summary: Zap is a simpler BOOM. Plus, it's one character shorter!
|
109
|
+
test_files: []
|
110
|
+
|