skipdir 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cefd6a2020988b3e49a7d1b4f616b4a6806fbac7
4
+ data.tar.gz: e7b36f3e3153e16fcda3aca019fea45a02759cc2
5
+ SHA512:
6
+ metadata.gz: 69543260fe11aded34d27c83d85b945c4ef32150f550300aa61892c46e06f4035b7c17a0dfad667e8d7453eb1f9e76c10f8a0ba4c5f489181ffa8645a49a5c92
7
+ data.tar.gz: c709e5b5f21ba6f2e7af23337d9142c70e9e8e5fb8d0086bdab7f766d2208b73824f7a24229a655c800482fb886dcb0031a9b3cf293aaa97b352c0a6f78b3e77
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,16 @@
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 "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0"
12
+ gem "jeweler", "~> 2.0.1"
13
+ gem "simplecov", ">= 0"
14
+ end
15
+
16
+ gem 'thor', "~>0.19"
@@ -0,0 +1,82 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.2.0)
5
+ i18n (~> 0.7)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.3, >= 0.3.4)
9
+ tzinfo (~> 1.1)
10
+ addressable (2.3.7)
11
+ builder (3.2.2)
12
+ descendants_tracker (0.0.4)
13
+ thread_safe (~> 0.3, >= 0.3.1)
14
+ docile (1.1.5)
15
+ faraday (0.9.1)
16
+ multipart-post (>= 1.2, < 3)
17
+ git (1.2.9.1)
18
+ github_api (0.12.3)
19
+ addressable (~> 2.3)
20
+ descendants_tracker (~> 0.0.4)
21
+ faraday (~> 0.8, < 0.10)
22
+ hashie (>= 3.3)
23
+ multi_json (>= 1.7.5, < 2.0)
24
+ nokogiri (~> 1.6.3)
25
+ oauth2
26
+ hashie (3.4.0)
27
+ highline (1.7.1)
28
+ i18n (0.7.0)
29
+ jeweler (2.0.1)
30
+ builder
31
+ bundler (>= 1.0)
32
+ git (>= 1.2.5)
33
+ github_api
34
+ highline (>= 1.6.15)
35
+ nokogiri (>= 1.5.10)
36
+ rake
37
+ rdoc
38
+ json (1.8.2)
39
+ jwt (1.3.0)
40
+ mini_portile (0.6.2)
41
+ minitest (5.5.1)
42
+ multi_json (1.10.1)
43
+ multi_xml (0.5.5)
44
+ multipart-post (2.0.0)
45
+ nokogiri (1.6.6.2)
46
+ mini_portile (~> 0.6.0)
47
+ oauth2 (1.0.0)
48
+ faraday (>= 0.8, < 0.10)
49
+ jwt (~> 1.0)
50
+ multi_json (~> 1.3)
51
+ multi_xml (~> 0.5)
52
+ rack (~> 1.2)
53
+ rack (1.6.0)
54
+ rake (10.4.2)
55
+ rdoc (3.12.2)
56
+ json (~> 1.4)
57
+ shoulda (3.5.0)
58
+ shoulda-context (~> 1.0, >= 1.0.1)
59
+ shoulda-matchers (>= 1.4.1, < 3.0)
60
+ shoulda-context (1.2.1)
61
+ shoulda-matchers (2.8.0)
62
+ activesupport (>= 3.0.0)
63
+ simplecov (0.9.2)
64
+ docile (~> 1.1.0)
65
+ multi_json (~> 1.0)
66
+ simplecov-html (~> 0.9.0)
67
+ simplecov-html (0.9.0)
68
+ thor (0.19.1)
69
+ thread_safe (0.3.4)
70
+ tzinfo (1.2.2)
71
+ thread_safe (~> 0.1)
72
+
73
+ PLATFORMS
74
+ ruby
75
+
76
+ DEPENDENCIES
77
+ bundler (~> 1.0)
78
+ jeweler (~> 2.0.1)
79
+ rdoc (~> 3.12)
80
+ shoulda
81
+ simplecov
82
+ thor (~> 0.19)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 fhur
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.
@@ -0,0 +1,19 @@
1
+ = skipdir
2
+
3
+ Simple utility to manage bookmarked directories.
4
+
5
+ == Contributing to skipdir
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * 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.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2015 fhur. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,51 @@
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://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "skipdir"
18
+ gem.homepage = "http://github.com/fhur/skipdir"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Command line utility to manage bookmarked directories}
21
+ gem.description = gem.summary
22
+ gem.email = "fernandohur@gmail.com"
23
+ gem.authors = ["fhur"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "skipdir #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/sd ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'thor'
4
+ require 'skipdir.rb'
5
+
6
+ class SkipDirCli < Thor
7
+
8
+ LOCATION = "#{Dir.home}/.skipdir"
9
+
10
+ desc 'add ${alias}', 'Adds the current directory to the bookmark with the given alias'
11
+ def add(name, dir=Dir.pwd)
12
+ if name.strip.split(' ').size > 1
13
+ STDERR.puts 'Spaces not allowed for aliases'
14
+ end
15
+ puts "Adding alias '#{name}' => '#{dir}'"
16
+
17
+ @skipdir = SkipDir.new(LOCATION)
18
+ @skipdir.add name, dir
19
+ end
20
+
21
+ desc 'go ${alias}', "cd's to the given alias' directory"
22
+ def go(name)
23
+ @skipdir = SkipDir.new(LOCATION)
24
+ dir = @skipdir.get name
25
+ if dir.nil?
26
+ STDERR.puts "Alias #{name} not found"
27
+ else
28
+ Dir.chdir(dir)
29
+ end
30
+ end
31
+
32
+ desc 'list', "Shows a list of all saved bookmarks with their alias"
33
+ def list()
34
+ @skipdir = SkipDir.new(LOCATION)
35
+ max_key_len = @skipdir.all.map { |entry| entry[0].size }.max
36
+ @skipdir.all.each do |key, value|
37
+ puts key + ([" "] * (max_key_len + 1 - key.size)).join + value
38
+ end
39
+ end
40
+
41
+ desc 'rm ${alias}', "Removes the given alias"
42
+ def remove(name)
43
+ @skipdir = SkipDir.new(LOCATION)
44
+ unless @skipdir.remove(name)
45
+ STDERR.puts "No alias was found"
46
+ end
47
+ end
48
+
49
+ default_task :go
50
+
51
+ end
52
+ SkipDirCli.start ARGV
@@ -0,0 +1,84 @@
1
+ require 'set'
2
+
3
+ class SkipDir
4
+
5
+ def initialize(location)
6
+ @location = location
7
+ unless File.exist? @location
8
+ File.open(@location, 'w') do end
9
+ end
10
+
11
+ @entries = read_map
12
+ end
13
+
14
+ # Adds a mapping from the given name to the given directory
15
+ # @return a list of all current mappings as an array
16
+ def add(name, dir)
17
+ @entries[name.to_s] = dir.to_s
18
+ save_map
19
+ return @entries
20
+ end
21
+
22
+ # The current mapping for the given alias or nil if there is no mapping
23
+ def get(name)
24
+ entry = @entries[name]
25
+ if entry
26
+ return entry
27
+ else
28
+ @entries.each do |name_alias, dir|
29
+ return dir if name_alias.start_with? name
30
+ end
31
+ end
32
+ return nil
33
+ end
34
+
35
+ # A list of all current mappings
36
+ def all
37
+ @entries
38
+ end
39
+
40
+
41
+ # removes the entry with the given name.
42
+ # @return the removed dir or nil if no entry was found with that name
43
+ def remove(name)
44
+ if @entries.include? name
45
+ dir = @entries[name]
46
+ @entries.delete name
47
+ save_map
48
+ return dir
49
+ else
50
+ return nil
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ # Reads from the file at @location (which is expected to exist)
57
+ # and creates a map. This file should be composed of lines where each
58
+ # line is a "name value" pair. There can only be one " " character per line
59
+ # which is the separation character.
60
+ def read_map
61
+ file = File.read(@location)
62
+
63
+ lines = file.split("\n")
64
+ entries = {}
65
+ lines.each do |line|
66
+ entry = line.gsub("alias 'sd-",'')
67
+ .gsub("'cd ",'')
68
+ .gsub("'",'')
69
+ .split("=")
70
+ entries[entry[0]] = entry[1]
71
+ end
72
+
73
+ return entries
74
+ end
75
+
76
+ # Saves the current @entries map to the file at @location
77
+ def save_map
78
+ File.open(@location, 'w') do |file|
79
+ @entries.each do |key, value|
80
+ file.write "alias 'sd-#{key}'='cd #{value}'\n"
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,58 @@
1
+ require 'minitest/autorun'
2
+ require 'skipdir.rb'
3
+
4
+ describe SkipDir do
5
+
6
+ before :each do
7
+ @location = "./pkg/tmp-#{(rand*(10**15)).to_i}.skipdir"
8
+ @skipdir = SkipDir.new @location
9
+ end
10
+
11
+ after :each do
12
+ `rm #{@location}`
13
+ end
14
+
15
+ describe 'add' do
16
+ it 'should add a new entry to skipdir' do
17
+ @skipdir.add 'foo','./tmp/bar/foo/'
18
+ @skipdir.get('foo').wont_be_nil
19
+ end
20
+
21
+ it 'should return a map of all existing entries' do
22
+ entries = {
23
+ 'foo': './tmp/dir1',
24
+ 'bar': './tmp/dir2',
25
+ 'baz': './tmp/dir3'
26
+ }
27
+ entries.each do |key, val|
28
+ @skipdir.add key, val
29
+ end
30
+
31
+ stored_entries = @skipdir.add 'new','./dir/to/file'
32
+ stored_entries.size.must_equal 4
33
+ stored_entries['new'].must_equal './dir/to/file'
34
+ end
35
+ end
36
+
37
+ describe 'get' do
38
+ it 'should return nil for non existing entires' do
39
+ entry = @skipdir.get('some-non-existing-entry')
40
+ entry.must_equal nil
41
+ end
42
+
43
+ it 'should return the dir of an entry if it matches' do
44
+ entries = {
45
+ 'foo': './tmp/dir1',
46
+ 'bar': './tmp/dir2',
47
+ 'baz': './tmp/dir3'
48
+ }
49
+ entries.each do |key, val|
50
+ @skipdir.add key, val
51
+ end
52
+
53
+ @skipdir.get('foo').must_equal './tmp/dir1'
54
+ end
55
+
56
+ end
57
+
58
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: skipdir
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - fhur
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: shoulda
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Command line utility to manage bookmarked directories
98
+ email: fernandohur@gmail.com
99
+ executables:
100
+ - sd
101
+ extensions: []
102
+ extra_rdoc_files:
103
+ - LICENSE.txt
104
+ - README.rdoc
105
+ files:
106
+ - ".document"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.rdoc
111
+ - Rakefile
112
+ - VERSION
113
+ - bin/sd
114
+ - lib/skipdir.rb
115
+ - test/skipdir_spec.rb
116
+ homepage: http://github.com/fhur/skipdir
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Command line utility to manage bookmarked directories
140
+ test_files: []