yoke 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jelle Vandebeeck
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Yoke
2
+
3
+ Alias your current directory for fast directory access.
4
+
5
+ Create an alias for the current directory with a small 'yoke' command. And when you're somewhere else just type the name of the create alias and you'll be cd'ed to the director.
6
+
7
+ ## Installation
8
+
9
+ Install the gem:
10
+
11
+ $ gem install yoke
12
+
13
+ ## Usage
14
+
15
+ There are only 5 functions you can use with ths gem. We'll start with the beginning.
16
+
17
+ ### Help
18
+
19
+ Get an overview of all commands available with a small description.
20
+
21
+ yoke help
22
+
23
+ ### Setup
24
+
25
+ Prepare your current shell (bash or zsh) so that it loads the .yoke file every time you start a new shell.
26
+
27
+ yoke setup
28
+
29
+ ### up
30
+
31
+ Create a new alias for the current directory with the name of the current directory.
32
+
33
+ yoke
34
+ yoke up
35
+ yoke up the_alias_name
36
+
37
+ You can pass an extra parameter (the\_alias\_name) so that the alias will be this name instead of the current directory name.
38
+
39
+ ### down
40
+
41
+ Remove the alias that exists with the name of the current directory.
42
+
43
+ yoke down
44
+ yoke down the_alias_name
45
+
46
+ You can pass an extra parameter (the\_alias\_name) so that the alias with this name will be removed instead of the current directory name.
47
+
48
+ ### list
49
+
50
+ Show the list of aliases created with yoke.
51
+
52
+ yoke list
53
+
54
+ ## License
55
+
56
+ Check out the LICENSE.txt file. Really awesome reading material...
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/yoke ADDED
@@ -0,0 +1,30 @@
1
+ #! /usr/bin/ruby
2
+
3
+ require "thor"
4
+ require "yoke"
5
+
6
+ class YokeCommand < Thor
7
+ default_command :up
8
+
9
+ desc "up [NAME]", "Create the alias for the current directory with the current directory name or use the given name as the alias."
10
+ def up(name=nil)
11
+ Yoke::Base.add(name)
12
+ end
13
+
14
+ desc "down [NAME]", "Remove the alias for the current directory or remove the alias with the given name."
15
+ def down(name=nil)
16
+ Yoke::Base.remove(name)
17
+ end
18
+
19
+ desc "list", "List all the aliases."
20
+ def list
21
+ Yoke::Base.list
22
+ end
23
+
24
+ desc "setup", "Setup yoke with ZSH/BASH."
25
+ def setup
26
+ Yoke::Base.setup
27
+ end
28
+ end
29
+
30
+ YokeCommand.start
data/lib/yoke/alias.rb ADDED
@@ -0,0 +1,77 @@
1
+ module Yoke
2
+ class Alias
3
+ class << self
4
+ def list
5
+ return {} unless Yoke::Base.has_alias_file?
6
+
7
+ aliases = {}
8
+ File.readlines(Yoke::Base.alias_file_path).each do |line|
9
+ if line.start_with? "alias"
10
+ alias_extract = line.scan(/^alias\s(\w+)\=\"cd (.+)\"$/).last
11
+ aliases[alias_extract[0]] = alias_extract[1]
12
+ end
13
+ end
14
+ aliases
15
+ end
16
+
17
+ def add(path, name)
18
+ Yoke::Base.create_alias_file
19
+ if list.has_key?(name)
20
+ false
21
+ else
22
+ content = []
23
+ added = false
24
+ File.readlines(Yoke::Base.alias_file_path).each do |line|
25
+ if line.start_with? "alias"
26
+ alias_extract = line.scan(/^alias\s(\w+)\=\"cd (.+)\"$/).last
27
+ if alias_extract[1] == path
28
+ content << alias_string(name, path)
29
+ added = true
30
+ else
31
+ content << line
32
+ end
33
+ else
34
+ content << line
35
+ end
36
+ end
37
+ File.open(Yoke::Base.alias_file_path, "w") do |file|
38
+ content.each { |line| file.puts line }
39
+ end
40
+ unless added
41
+ File.open(Yoke::Base.alias_file_path, 'a') do |file|
42
+ file.puts alias_string(name, path)
43
+ end
44
+ end
45
+ true
46
+ end
47
+ end
48
+
49
+ def remove(path, name)
50
+ return false unless Yoke::Base.has_alias_file?
51
+
52
+ if list.has_key?(name)
53
+ content = []
54
+ File.readlines(Yoke::Base.alias_file_path).each do |line|
55
+ if line.start_with? "alias"
56
+ alias_extract = line.scan(/^alias\s(\w+)\=\"cd (.+)\"$/).last
57
+ if alias_extract[0] != name
58
+ content << line
59
+ end
60
+ else
61
+ content << line
62
+ end
63
+ end
64
+ File.open(Yoke::Base.alias_file_path, "w") do |file|
65
+ content.each { |line| file.puts line }
66
+ end
67
+ else
68
+ false
69
+ end
70
+ end
71
+
72
+ def alias_string(name, path)
73
+ "alias #{name.squish.downcase.tr(" ","_")}=\"cd #{path}\""
74
+ end
75
+ end
76
+ end
77
+ end
data/lib/yoke/base.rb ADDED
@@ -0,0 +1,143 @@
1
+ require "yoke/alias"
2
+ require "yoke/zsh"
3
+ require "yoke/bash"
4
+
5
+ module Yoke
6
+ class Base
7
+ FILENAME = ".yoke"
8
+
9
+ class << self
10
+ def setup
11
+ if %x[echo $SHELL].include?("zsh")
12
+ Yoke::Zsh.setup
13
+ else
14
+ Yoke::Bash.setup
15
+ end
16
+ end
17
+
18
+ def add(name=nil)
19
+ puts yoke_text
20
+
21
+ path = Dir.pwd
22
+ name = name || File.basename(path)
23
+ if Yoke::Alias.add(path, name)
24
+ puts_text("")
25
+ puts_text("Added #{name} as alias for #{path}")
26
+ else
27
+ puts_text("")
28
+ puts_text("The alias with #{name} already exists")
29
+ end
30
+ source_text
31
+ puts end_text
32
+ end
33
+
34
+ def remove(name=nil)
35
+ puts yoke_text
36
+
37
+ path = Dir.pwd
38
+ name = name || File.basename(path)
39
+ if Yoke::Alias.remove(path, name)
40
+ puts_text("")
41
+ puts_text("Removed #{name} as an alias")
42
+ else
43
+ puts_text("")
44
+ puts_text("The alias with #{name} is does not exist")
45
+ end
46
+ delete_text(name)
47
+ puts end_text
48
+ end
49
+
50
+ def list
51
+ puts yoke_text
52
+
53
+ list = Yoke::Alias.list
54
+ if list.count > 0
55
+ puts_text("")
56
+ puts_text("Listing all aliases")
57
+ puts_text("")
58
+ longest_word_count = list.keys.group_by(&:size).max.last.last.size
59
+ list.each do |alias_link, path|
60
+ printf "### %-#{longest_word_count}s %s %-#{sharp_count - 9 - longest_word_count - path.size}s###\n", alias_link, path, ""
61
+ end
62
+ else
63
+ puts_text("")
64
+ puts_text("No aliases to list")
65
+ end
66
+ puts_text("")
67
+ puts end_text
68
+ end
69
+
70
+ def directory?(path)
71
+ File.directory?(path)
72
+ end
73
+
74
+ def alias_file_path
75
+ File.join(Dir.home, FILENAME)
76
+ end
77
+
78
+ def has_alias_file?
79
+ File.exists?(alias_file_path)
80
+ end
81
+
82
+ def create_alias_file
83
+ unless has_alias_file?
84
+ puts_text("")
85
+ puts_text("Generated #{FILENAME} file")
86
+ File.open(alias_file_path, "w") { |f| f.write(empty_file_contents) }
87
+ end
88
+ end
89
+
90
+ def empty_file_contents
91
+ <<TEXT
92
+ # File generated by Yoke (http://fousa.be/apps/yoke).
93
+ #
94
+ # Do not alter this file or yoke will stop working correctly.
95
+ #
96
+ TEXT
97
+ end
98
+
99
+ def yoke_text
100
+ <<TEXT
101
+ #############################################################################################################
102
+ ### YOKE ####################################################################################################
103
+ #############################################################################################################
104
+ TEXT
105
+ end
106
+
107
+ def end_text
108
+ <<TEXT
109
+ #############################################################################################################
110
+ TEXT
111
+ end
112
+
113
+ def delete_text(alias_name)
114
+ puts_text("")
115
+ puts_text("To remove this alias immediately run the following command:")
116
+ puts_text("")
117
+ puts_text("unalias #{alias_name}")
118
+ puts_text("")
119
+ puts_text("Or just start another shell and the aliases are reloaded for you!")
120
+ puts_text("")
121
+ end
122
+
123
+ def source_text
124
+ puts_text("")
125
+ puts_text("You should reload the 'yoke' aliases defined in your .yoke file.")
126
+ puts_text("You can do this by executing the following command:")
127
+ puts_text("")
128
+ puts_text("source ~/.yoke")
129
+ puts_text("")
130
+ puts_text("Or just start another shell and the aliases are reloaded for you!")
131
+ puts_text("")
132
+ end
133
+
134
+ def sharp_count
135
+ "#############################################################################################################".size
136
+ end
137
+
138
+ def puts_text(text)
139
+ printf "### %-#{sharp_count - 8}s ###\n", text
140
+ end
141
+ end
142
+ end
143
+ end
data/lib/yoke/bash.rb ADDED
@@ -0,0 +1,17 @@
1
+ module Yoke
2
+ class Bash
3
+ class << self
4
+ def custom_path
5
+ File.join(Dir.home)
6
+ end
7
+
8
+ def setup
9
+ unless File.exists?(custom_path)
10
+ File.open(custom_path, 'a') do |file|
11
+ file.puts "source ~/#{Yoke::Base::FILENAME}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Yoke
2
+ VERSION = "0.1"
3
+ end
data/lib/yoke/zsh.rb ADDED
@@ -0,0 +1,17 @@
1
+ module Yoke
2
+ class Zsh
3
+ class << self
4
+ def custom_path
5
+ File.join(Dir.home, ".oh-my-zsh/custom/yoke.zsh")
6
+ end
7
+
8
+ def setup
9
+ unless File.exists?(custom_path)
10
+ File.open(custom_path, 'a') do |file|
11
+ file.puts "source ~/#{Yoke::Base::FILENAME}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
data/lib/yoke.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "yoke/version"
2
+ require "yoke/base"
3
+
4
+ module Yoke
5
+ end
data/yoke.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yoke/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yoke"
8
+ spec.version = Yoke::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = ["Jelle Vandebeeck"]
11
+ spec.email = ["jelle@fousa.be"]
12
+ spec.description = %q{Alias your current directory for fast directory access.}
13
+ spec.summary = %q{Create an alias for the current directory with a small 'yoke' command. And when you're somewhere else just type the name of the create alias and you'll be cd'ed to the director.}
14
+ spec.homepage = "https://github.com/fousa/yoke"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_dependency 'thor', '0.18.1'
26
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yoke
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jelle Vandebeeck
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
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: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
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: rspec
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: thor
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.18.1
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.18.1
78
+ description: Alias your current directory for fast directory access.
79
+ email:
80
+ - jelle@fousa.be
81
+ executables:
82
+ - yoke
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/yoke
92
+ - lib/yoke.rb
93
+ - lib/yoke/alias.rb
94
+ - lib/yoke/base.rb
95
+ - lib/yoke/bash.rb
96
+ - lib/yoke/version.rb
97
+ - lib/yoke/zsh.rb
98
+ - yoke.gemspec
99
+ homepage: https://github.com/fousa/yoke
100
+ licenses:
101
+ - MIT
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 1.8.25
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: Create an alias for the current directory with a small 'yoke' command. And
124
+ when you're somewhere else just type the name of the create alias and you'll be
125
+ cd'ed to the director.
126
+ test_files: []