sheet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec"
10
+ gem "yard"
11
+ gem "rdoc"
12
+ gem "jeweler"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.8.3)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rdoc
11
+ json (1.6.6)
12
+ rake (0.9.2.2)
13
+ rdoc (3.12)
14
+ json (~> 1.4)
15
+ rspec (2.9.0)
16
+ rspec-core (~> 2.9.0)
17
+ rspec-expectations (~> 2.9.0)
18
+ rspec-mocks (~> 2.9.0)
19
+ rspec-core (2.9.0)
20
+ rspec-expectations (2.9.1)
21
+ diff-lcs (~> 1.1.3)
22
+ rspec-mocks (2.9.0)
23
+ yard (0.7.5)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ jeweler
30
+ rdoc
31
+ rspec
32
+ yard
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Oscar Del Ben
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # Sheet
2
+
3
+ Easily create and access snippets of text from your terminal. `sheet` is
4
+ your own personal wiki.
5
+
6
+ ```
7
+ gem install sheet
8
+ ```
9
+
10
+ Examples:
11
+ ```
12
+ sheet # with no arguments it will just list all your sheets
13
+ sheet git # opens git sheet
14
+ sheet new git # creates git sheet
15
+ sheet edit git # edit git sheet
16
+ ```
17
+
18
+ Use `sheet new <term>` to create your first sheet. Useful for jotting
19
+ down commands that you use often but somehow never remember.
20
+
21
+ ### Opening urls
22
+
23
+ Found a great cheat sheet *online* about jquery or your favorite
24
+ language? I've got you covered.
25
+
26
+ When writing your snippet, you can use this special format to
27
+ automatically open a url when opening your sheet:
28
+
29
+ ```
30
+ url: http://example/com
31
+ ```
32
+
33
+ Make sure that's you don't have trailing lines and sheet will
34
+ automatically open that url for you
35
+
36
+ Please note that to open urls, sheet will use the `open` command on mac
37
+ os x and `xdg-open` in linux. Patches welcome for other systems.
38
+
39
+ ### Behind the scenes
40
+
41
+ `sheet` stores your sheets in text files in the
42
+ `~/.sheets` directory. You can go there and modify the files manually if you desire,
43
+ or you can source them into version control and share them across
44
+ multiple systems.
45
+
46
+ For writing files, `sheet` looks for the `$EDITOR` global variable, and
47
+ will raise an error if no editor was found.
48
+
49
+ ### Help your stuff is broken
50
+
51
+ I tested this software in mac os x with Ruby 1.9. If you find any bug
52
+ with other platforms/interpreters please let me know and I'll push a
53
+ fix.
54
+
55
+ ### Contributing to sheet
56
+
57
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
58
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
59
+ * Fork the project.
60
+ * Start a feature/bugfix branch.
61
+ * Commit and push until you are happy with your contribution.
62
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
63
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
64
+
65
+ ### Copyright
66
+
67
+ Copyright (c) 2012 Oscar Del Ben. See LICENSE.txt for
68
+ further details.
69
+
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "sheet"
18
+ gem.homepage = "http://github.com/oscardelben/sheet"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{snippets for your command line}
21
+ gem.description = %Q{sheets allows you to store and browse snippets of text from your command line.}
22
+ gem.email = "info@oscardelben.com"
23
+ gem.authors = ["Oscar Del Ben"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'yard'
42
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/sheet ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), '../lib/sheet')
4
+
5
+ Sheet.new(ARGV).process
data/lib/sheet/list.rb ADDED
@@ -0,0 +1,9 @@
1
+
2
+ class Sheet
3
+ class List
4
+
5
+ def list
6
+ Sheet.exec("ls #{Sheet.sheets_dir}")
7
+ end
8
+ end
9
+ end
data/lib/sheet/open.rb ADDED
@@ -0,0 +1,44 @@
1
+ class Sheet
2
+
3
+ class Open
4
+
5
+ attr_accessor :name
6
+
7
+ def initialize(name)
8
+ @name = name
9
+ end
10
+
11
+ def open
12
+ if Sheet.sheet_exists?(name)
13
+ process_sheet_content
14
+ else
15
+ Sheet.write "A cheat named #{name} doesn't exist.\nYou can create one with sheet new #{name}"
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def process_sheet_content
22
+ if contains_url_format? && cmd = Sheet.open_command
23
+ # TODO: check if open is available
24
+ Sheet.exec "#{cmd} #{extract_url}"
25
+ else
26
+ Sheet.write sheet_content
27
+ end
28
+ end
29
+
30
+ def contains_url_format?
31
+ sheet_content.split("\n").size == 1 &&
32
+ sheet_content =~ /^url:\s*http.+$/
33
+ end
34
+
35
+ def extract_url
36
+ sheet_content.match(/(http.+)$/)[1]
37
+ end
38
+
39
+ def sheet_content
40
+ @sheet_content ||= File.read(Sheet.sheet_path(name))
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,30 @@
1
+
2
+ class Sheet::Write
3
+
4
+ attr_accessor :name
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ end
9
+
10
+ def write
11
+ create_dir_if_doesnt_exist
12
+ if editor_is_set?
13
+ Sheet.exec("#{Sheet.editor} #{Sheet.sheet_path(name)}", true)
14
+ else
15
+ Sheet.write "Please set the $EDITOR variable to write files"
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def editor_is_set?
22
+ (editor = Sheet.editor) && editor.length > 0
23
+ end
24
+
25
+ def create_dir_if_doesnt_exist
26
+ if ! Dir.exists?(Sheet.sheets_dir)
27
+ Dir.mkdir(Sheet.sheets_dir)
28
+ end
29
+ end
30
+ end
data/lib/sheet.rb ADDED
@@ -0,0 +1,99 @@
1
+
2
+ # The Sheet class allows to easily dispatch commands from the command
3
+ # line. It also provides common functionality for other classes.
4
+
5
+ require 'sheet/open'
6
+ require 'sheet/write'
7
+ require 'sheet/list'
8
+
9
+ class Sheet
10
+
11
+ SHEETS_DIR = '~/.sheets/'.freeze
12
+
13
+ class << self
14
+ # Utility to write to standard output
15
+ def write(message)
16
+ puts message
17
+ end
18
+
19
+ # Utility to execute system commands
20
+ def exec(cmd, replace_current_process=false)
21
+ if replace_current_process
22
+ Kernel.exec cmd
23
+ else
24
+ %x!#{cmd}!
25
+ end
26
+ end
27
+
28
+ # @param [String] name the sheet name
29
+ # @return [String]
30
+ # Returns the path of a sheet, doesn't check if the file exists
31
+ def sheet_path(name)
32
+ File.join(sheets_dir, name)
33
+ end
34
+
35
+ # Where the sheets directory is (absolute path)
36
+ def sheets_dir
37
+ File.expand_path(SHEETS_DIR)
38
+ end
39
+
40
+ # @param [String] name the sheet name
41
+ # @return [true]
42
+ # Used to check if a sheet exists
43
+ def sheet_exists?(name)
44
+ name && File.exists?(sheet_path(name))
45
+ end
46
+
47
+ # @return [String]
48
+ # Used to check the preferred editor for the user
49
+ def editor
50
+ exec("echo $EDITOR").chomp
51
+ end
52
+
53
+ # If we're using mac, we should use open to open urls.
54
+ # If we're using linux, we can probably use xdg-open
55
+ # Otherwise return nil
56
+ def open_command
57
+ if RUBY_PLATFORM =~ /darwin/
58
+ 'open'
59
+ elsif RUBY_PLATFORM =~ /linux/
60
+ 'xdg-open'
61
+ else
62
+ nil
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ # Creates a new instance of Sheet, usually followed by a call to {#process}
69
+ # @param [Array] args command line options
70
+ def initialize(*args)
71
+ @args = args.flatten
72
+ end
73
+
74
+ # Where the dispatching really happens. We check to see what the user
75
+ # intended to do and then instantiate the proper class
76
+ def process
77
+ if ['new', 'edit'].include?(@args[0])
78
+ write(@args[1])
79
+ elsif ['ls', 'list'].include?(@args[0])
80
+ list
81
+ else
82
+ open(@args[0])
83
+ end
84
+ end
85
+
86
+ private
87
+
88
+ def open(name)
89
+ Sheet::Open.new(name).open
90
+ end
91
+
92
+ def write(name)
93
+ Sheet::Write.new(name).write
94
+ end
95
+
96
+ def list
97
+ Sheet::List.new.list
98
+ end
99
+ end
@@ -0,0 +1,13 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe Sheet::List do
5
+
6
+ it 'calls system ls' do
7
+ cmd = "ls #{Sheet.sheets_dir}"
8
+ Sheet.should_receive(:exec).with(cmd)
9
+
10
+ Sheet::List.new.list
11
+ end
12
+
13
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sheet::Open do
4
+
5
+ it "should show a message when the app doesn't exist" do
6
+ message = "A cheat named rails doesn't exist.\nYou can create one with sheet new rails"
7
+ Sheet.should_receive(:write).with(message)
8
+
9
+ Sheet::Open.new('rails').open
10
+ end
11
+
12
+ it "should output the sheet content" do
13
+ message = "My sheet about git"
14
+ Sheet.should_receive(:write).with(message)
15
+
16
+ s = Sheet::Open.new('git')
17
+ Sheet.stub(:sheet_exists?).with('git') { true }
18
+ s.stub(:sheet_content) { message }
19
+ s.open
20
+ end
21
+
22
+ it "should open a url" do
23
+ Sheet.stub(:open_command) { 'open' }
24
+ message = "url: http://example.com"
25
+ Sheet.should_receive(:exec).with('open http://example.com')
26
+
27
+ s = Sheet::Open.new('git')
28
+ Sheet.stub(:sheet_exists?).with('git') { true }
29
+ s.stub(:sheet_content) { message }
30
+ s.open
31
+ end
32
+
33
+ it "should fallback to showing the content if an open command is not present" do
34
+ Sheet.stub(:open_command) { nil}
35
+ message = "url: http://example.com"
36
+ Sheet.should_receive(:puts).with('url: http://example.com')
37
+
38
+ s = Sheet::Open.new('git')
39
+ Sheet.stub(:sheet_exists?).with('git') { true }
40
+ s.stub(:sheet_content) { message }
41
+ s.open
42
+ end
43
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sheet do
4
+
5
+ describe 'opening sheets' do
6
+ it 'should instantiate Sheet::Open' do
7
+ open = double('Sheet::Open')
8
+ open.should_receive(:open)
9
+
10
+ Sheet::Open.stub(:new).with('cucumber') { open }
11
+ Sheet.new('cucumber').process
12
+ end
13
+ end
14
+
15
+ describe 'creating sheets' do
16
+ it 'should instantiate Sheet::Write' do
17
+ write = double('Sheet::Write')
18
+ write.should_receive(:write)
19
+
20
+ Sheet::Write.stub(:new).with('rails') { write }
21
+ Sheet.new('new', 'rails').process
22
+ end
23
+ end
24
+
25
+ describe 'editing sheets' do
26
+ it 'should instantiate Sheet::Write' do
27
+ write = double('Sheet::Write')
28
+ write.should_receive(:write)
29
+
30
+ Sheet::Write.stub(:new).with('rails') { write }
31
+ Sheet.new('edit', 'rails').process
32
+ end
33
+ end
34
+
35
+ describe 'list sheets' do
36
+ it 'should instantiate Sheet::List' do
37
+ list = double('Sheet::List')
38
+ list.should_receive(:list)
39
+
40
+ Sheet::List.stub(:new) { list }
41
+ Sheet.new('ls').process
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sheet::Write do
4
+
5
+ let (:editor) { 'vim' }
6
+
7
+ it 'opens a new file for writing' do
8
+ cmd = "#{editor} #{Sheet.sheet_path('tmux')}"
9
+ Sheet.should_receive(:exec).with(cmd, true)
10
+
11
+ Sheet.stub(:editor) { editor }
12
+
13
+ Sheet::Write.new('tmux').write
14
+ end
15
+
16
+ it 'returns an error if no editor is found' do
17
+ Sheet.stub(:editor) { nil }
18
+ Sheet.should_receive(:write).with { "Please set the $EDITOR variable to write files" }
19
+
20
+ Sheet::Write.new('tmux').write
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'sheet'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sheet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Oscar Del Ben
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: yard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: jeweler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: sheets allows you to store and browse snippets of text from your command
79
+ line.
80
+ email: info@oscardelben.com
81
+ executables:
82
+ - sheet
83
+ extensions: []
84
+ extra_rdoc_files:
85
+ - LICENSE.txt
86
+ - README.md
87
+ files:
88
+ - .document
89
+ - .rspec
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - VERSION
96
+ - bin/sheet
97
+ - lib/sheet.rb
98
+ - lib/sheet/list.rb
99
+ - lib/sheet/open.rb
100
+ - lib/sheet/write.rb
101
+ - spec/sheet/list_spec.rb
102
+ - spec/sheet/open_spec.rb
103
+ - spec/sheet/sheet_spec.rb
104
+ - spec/sheet/write_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: http://github.com/oscardelben/sheet
107
+ licenses:
108
+ - MIT
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ segments:
120
+ - 0
121
+ hash: 2530773601907253271
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 1.8.21
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: snippets for your command line
134
+ test_files: []