spath 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5594e6a86f11550e680bd16f75370edde09eb132
4
+ data.tar.gz: ac0b0c48d7e5ee6ab93a49c1e5ba13306519c151
5
+ SHA512:
6
+ metadata.gz: 34b27d6977ff187dfec0dd4ad1e8dd59f18ebb51b6b8f512e6634dc5830943a0577724330c801f807c7d18fae3e5cc46665e98cb9ae3292727a39d5a57fee5b3
7
+ data.tar.gz: 4b0c0984f7b621cf7fa90a88f899361a6a27d0e0e47eac39af8718e4f705a7d9f3574fed12759291cdbae7e2799ee0416d2af360adecbdcd5e0a2d702d977d83
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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jack Willis
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,48 @@
1
+ # SPath
2
+
3
+ 'short path'
4
+
5
+ Use shortcuts when 'cd'ing on the command line.
6
+ (this probably already exists)
7
+
8
+ Written in Ruby.
9
+
10
+ ## Installation
11
+
12
+ Install it as:
13
+
14
+ $ gem install spath
15
+
16
+ Add this to your .bashrc:
17
+
18
+ function c(){cd $(spath c $*||echo .)}
19
+
20
+ ( This is required because a Ruby script can not change the working directory of its parent process. )
21
+
22
+ ## To do:
23
+
24
+ Add configuration options.
25
+
26
+ ## Usage
27
+
28
+ Create shortcuts for common places with the command 's [nick] [path]'
29
+
30
+ you@computer ~ $ s foo ~/files/something/lol/whatever/ok
31
+
32
+ you@computer ~ $ cd /net/user/you/some/thing/releases/v01-02-03/doc/
33
+ you@computer ~ $ s ok .
34
+
35
+ then visit them with the shortcut you made with the command 'c [nick]'.
36
+
37
+ you@computer ~ $ c foo
38
+ you@computer ~/files/something/lol/whatever/ok $
39
+
40
+ List all available shortcuts with the command 'l'.
41
+
42
+ you@computer ~ $ l
43
+ l: list spath shortcuts.
44
+ ok => /net/user/you/some/thing/releases/v01-02-03/doc/
45
+ abin => /usr/share/Adobe/doc/example/android_vm/root/sbin
46
+ foo => /home/you/files/something/lol/whatever/ok
47
+
48
+ Shortcuts are stored at ~/.spath in YAML format.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default do
4
+ puts "nothing to do"
5
+ end
data/bin/c ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ # ruby command can not change directory by itself
4
+ echo "attempt cd $(spath c $*)"
5
+ cd $(spath c $*)
data/bin/l ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ # l: list shortcuts
5
+
6
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../lib")
7
+ require "spath"
8
+
9
+ abort unless ARGV.empty?
10
+
11
+ puts "l: list spath shortcuts."
12
+
13
+ config_file = SPath::ConfigFile.load
14
+ shortcuts = config_file.shortcuts
15
+
16
+ shortcuts.each { |s| puts "#{s.nickname.to_s.rjust(8)} => #{s.path}" }
data/bin/s ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ # s: create shortcut
5
+
6
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../lib")
7
+ require "spath"
8
+
9
+ nickname, path = ARGV
10
+ abort "s: create spath shortcut. Usage: s [nickname] [path]" \
11
+ unless nickname and path
12
+
13
+ path = File.expand_path(path)
14
+ abort "s: error: #{path} is not a valid path. :(" unless File.exists? path
15
+
16
+ config_file = SPath::ConfigFile.load
17
+ config_file << SPath::Shortcut.new(nickname, path)
18
+ config_file.write!
data/bin/spath ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ # spath: provide all functions, about message, configuration
5
+
6
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../lib")
7
+ require "spath"
8
+
9
+ def usage
10
+ abort "spath: create shortcuts. Usage: `spath c [nick]`."
11
+ end
12
+
13
+ usage unless (mode = ARGV[0])
14
+
15
+ case mode
16
+ when "c"
17
+
18
+ usage unless (nickname = ARGV[1])
19
+
20
+ config_file = SPath::ConfigFile.load
21
+ begin
22
+ puts config_file.path_for(nickname)
23
+ rescue ArgumentError => msg
24
+ abort "spath: error: #{msg}"
25
+ end
26
+
27
+ else
28
+ usage
29
+ end
@@ -0,0 +1,3 @@
1
+ module SPath
2
+ VERSION = "0.0.1"
3
+ end
data/lib/spath.rb ADDED
@@ -0,0 +1,84 @@
1
+ require "yaml"
2
+ require "spath/version"
3
+
4
+ module SPath
5
+ DEFAULT_CONFIG_PATH = File.expand_path("~/.spath")
6
+
7
+ class ConfigFile
8
+
9
+ attr_accessor :path, :shortcuts, :options
10
+
11
+ def initialize(path = DEFAULT_CONFIG_PATH, shortcuts = [], options = {})
12
+ @path = File.expand_path(path)
13
+ @shortcuts = shortcuts
14
+ @options = options
15
+ end
16
+
17
+ def <<(shortcut)
18
+ raise ArgumentError "#{shortcut} is not a SPath::Shortcut" \
19
+ unless shortcut.is_a? Shortcut
20
+
21
+ # Make room for new shortcuts
22
+ @shortcuts.delete_if { |old_shortcut| shortcut.nickname == old_shortcut.nickname }
23
+
24
+ # Append to the array
25
+ @shortcuts << shortcut
26
+ end
27
+ alias_method :add_shortcut, :<<
28
+
29
+ def to_hash
30
+ { shortcuts: @shortcuts.map(&:to_hash), options: @options }
31
+ end
32
+
33
+ def write!
34
+ File.open(@path, "w") { |f| f.write(to_hash.to_yaml) }
35
+ end
36
+
37
+ def self.load(path = DEFAULT_CONFIG_PATH)
38
+ data = YAML.load(File.read(path))
39
+
40
+ # If config file returns empty, use the default
41
+ return new unless data
42
+
43
+ shortcuts = data[:shortcuts].map { |sdata| Shortcut[sdata] }
44
+ new(path, shortcuts, data[:options])
45
+ end
46
+
47
+ def path_for(nickname)
48
+ raise ArgumentError, "path does not exist for shortcut #{nickname}" unless \
49
+ (shortcut = @shortcuts.select { |s| s.nickname.to_s == nickname }.first)
50
+
51
+ shortcut.path
52
+ end
53
+
54
+ end
55
+
56
+ class Shortcut
57
+
58
+ attr_accessor :nickname, :path
59
+
60
+ def initialize(nickname, path)
61
+ raise ArgumentError, "#{nickname} is not alphanumeric" \
62
+ if nickname.to_s =~ /[^a-z0-9_]/i
63
+ raise ArgumentError, "nickname is not a string" \
64
+ unless nickname.respond_to? :to_s
65
+
66
+ path = File.expand_path(path)
67
+ raise ArgumentError, "path '#{path}' doesn't exist" \
68
+ unless File.exists? path
69
+
70
+ @nickname = nickname.to_s.to_sym
71
+ @path = path
72
+ end
73
+
74
+ def to_hash
75
+ { nickname: @nickname.to_s, path: @path }
76
+ end
77
+
78
+ # Create instance from hash
79
+ def self.[](data)
80
+ new(data[:nickname], data[:path])
81
+ end
82
+
83
+ end
84
+ end
data/spath.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spath/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spath"
8
+ spec.version = SPath::VERSION
9
+ spec.authors = ["Jack Willis"]
10
+ spec.email = ["jack@attac.us"]
11
+ spec.description = "spath creates shortcuts for paths"
12
+ spec.summary = "shortcuts for paths"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spath
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jack Willis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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
+ description: spath creates shortcuts for paths
42
+ email:
43
+ - jack@attac.us
44
+ executables:
45
+ - c
46
+ - l
47
+ - s
48
+ - spath
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - .gitignore
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - bin/c
57
+ - bin/l
58
+ - bin/s
59
+ - bin/spath
60
+ - lib/spath.rb
61
+ - lib/spath/version.rb
62
+ - spath.gemspec
63
+ homepage: ''
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.0.3
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: shortcuts for paths
87
+ test_files: []