medoc 1.0.0
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.
- checksums.yaml +7 -0
- data/README.md +48 -0
- data/bin/medoc +63 -0
- data/lib/medoc.rb +135 -0
- metadata +47 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 2cc495dc9325fa5da31205f20af23ce1211f4d96
|
|
4
|
+
data.tar.gz: c12e22d15989aa43d7786f435252707208a40397
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 43b166af257fa00c4fbf9b95ab8ccdc58ea9d07a92cee0f084e91ea4d0effc08a2144ff7abdce7daa50d7094bcd73dc0cb9bb0a52c309c74fa438521cf753bdf
|
|
7
|
+
data.tar.gz: db0ba4b73e5b196991ed2c9b1a08da0183eed377b16bad54f085012932c12c6b6de99bccf76a07e63f6dbcf0a798d0d611de75ffbb0fb39be6569fc60924aa89
|
data/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Medoc
|
|
2
|
+
|
|
3
|
+
Medoc is a tiny Ruby gem for managing you shell aliases. Jump to another directory in a clever way.
|
|
4
|
+
|
|
5
|
+
## Get started
|
|
6
|
+
|
|
7
|
+
To install Medoc, run this command:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
gem install medoc
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Once done, open your `.bash_profile` file, or another `profile` you are using with your shell. Then, append this code:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Medoc config
|
|
17
|
+
medoc_exec() {
|
|
18
|
+
cd "`/usr/bin/medoc $@`"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
alias medoc=medoc_exec
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Here you go! Run `medoc your-alias` to leap to a directory.
|
|
25
|
+
|
|
26
|
+
## Configuration file
|
|
27
|
+
|
|
28
|
+
Medoc lets user using a configuration file to define all his/her aliases: `~/.medoc.yml`.
|
|
29
|
+
|
|
30
|
+
When you are using Medoc for the first time, run `medoc --init` to automatically generate this file.
|
|
31
|
+
|
|
32
|
+
Config file is a simple YAML file. Here is a sample:
|
|
33
|
+
|
|
34
|
+
```yaml
|
|
35
|
+
my-first-alias: path/to/my/fabulous/directory
|
|
36
|
+
|
|
37
|
+
another-alias: path/to/another/directory
|
|
38
|
+
|
|
39
|
+
magic-alias:
|
|
40
|
+
- my-first-alias
|
|
41
|
+
- path/to/random/directory # Relative to previous one
|
|
42
|
+
- another-alias
|
|
43
|
+
- path/to/somewhere
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
As you may have seen, you can define an alias using two ways. First one is the simplest: just specify the path to your directory.
|
|
47
|
+
|
|
48
|
+
Other way is an array mixing aliases and directories. Use here existing aliases and normal directories. Medoc will get the job done for you.
|
data/bin/medoc
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'medoc'
|
|
3
|
+
#require 'pry'
|
|
4
|
+
|
|
5
|
+
def no_cd
|
|
6
|
+
$stdout.puts ''
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def version
|
|
10
|
+
$stderr.puts "Medoc #{Medoc.version} - Adrien Cadet"
|
|
11
|
+
no_cd
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def help
|
|
15
|
+
$stderr.puts "
|
|
16
|
+
Medoc lets you define shortcuts to jump quickly to another directory.
|
|
17
|
+
|
|
18
|
+
Usage:
|
|
19
|
+
medoc \"<alias>\"
|
|
20
|
+
Where
|
|
21
|
+
alias: alias to run.
|
|
22
|
+
|
|
23
|
+
Options:
|
|
24
|
+
--init Initializes Medoc config file
|
|
25
|
+
--help Displays this message
|
|
26
|
+
--version Gets current version
|
|
27
|
+
"
|
|
28
|
+
no_cd
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
if ARGV.size < 1
|
|
32
|
+
help
|
|
33
|
+
else
|
|
34
|
+
arg = ARGV[0]
|
|
35
|
+
|
|
36
|
+
if arg == '--version'
|
|
37
|
+
version
|
|
38
|
+
elsif arg == '--help'
|
|
39
|
+
help
|
|
40
|
+
elsif arg == '--init'
|
|
41
|
+
begin
|
|
42
|
+
Medoc.init
|
|
43
|
+
$stderr.puts "Created #{Medoc.config_file}"
|
|
44
|
+
no_cd
|
|
45
|
+
rescue MedocError => e
|
|
46
|
+
$stderr.puts e.embedded_message
|
|
47
|
+
no_cd
|
|
48
|
+
rescue => e
|
|
49
|
+
$stderr.puts e.message
|
|
50
|
+
no_cd
|
|
51
|
+
end
|
|
52
|
+
else
|
|
53
|
+
begin
|
|
54
|
+
$stdout.puts File.expand_path(Medoc.run arg)
|
|
55
|
+
rescue MedocError => e
|
|
56
|
+
$stderr.puts e.embedded_message
|
|
57
|
+
no_cd
|
|
58
|
+
rescue => e
|
|
59
|
+
$stderr.puts e.message
|
|
60
|
+
no_cd
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
data/lib/medoc.rb
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
#require 'pry'
|
|
3
|
+
|
|
4
|
+
class MedocError < Exception
|
|
5
|
+
|
|
6
|
+
def initialize(message = 'Unknown MedocError')
|
|
7
|
+
super message
|
|
8
|
+
@embedded_message = message
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def embedded_message
|
|
12
|
+
@embedded_message
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def embedded_message=(value)
|
|
16
|
+
@embedded_message = value
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class Medoc
|
|
21
|
+
|
|
22
|
+
###
|
|
23
|
+
# Path to config file
|
|
24
|
+
##
|
|
25
|
+
@@config_file = File.expand_path '~/.medoc.yml'
|
|
26
|
+
|
|
27
|
+
###
|
|
28
|
+
# Loaded config
|
|
29
|
+
##
|
|
30
|
+
@@config = nil
|
|
31
|
+
|
|
32
|
+
###
|
|
33
|
+
# Returns current version
|
|
34
|
+
##
|
|
35
|
+
def self.version
|
|
36
|
+
'1.0.0'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
###
|
|
40
|
+
# Returns path to config file
|
|
41
|
+
##
|
|
42
|
+
def self.config_file
|
|
43
|
+
@@config_file
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
###
|
|
47
|
+
# Creates default config file
|
|
48
|
+
##
|
|
49
|
+
def self.init
|
|
50
|
+
if !File.exists? @@config_file
|
|
51
|
+
f = File.new @@config_file, "w"
|
|
52
|
+
f.puts '#############################################'
|
|
53
|
+
f.puts '### Medoc config file ###'
|
|
54
|
+
f.puts '### ###'
|
|
55
|
+
f.puts '### Visit https://github.com/acadet/medoc ###'
|
|
56
|
+
f.puts '### to know more about this file ###'
|
|
57
|
+
f.puts '#############################################'
|
|
58
|
+
else
|
|
59
|
+
raise MedocError.new "Error: config file is already existing."
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
###
|
|
64
|
+
# Main method. Returns full path matching provided alias
|
|
65
|
+
##
|
|
66
|
+
def self.run(keyword)
|
|
67
|
+
if !Medoc.load_config
|
|
68
|
+
# No existing config file
|
|
69
|
+
raise MedocError.new 'Error: no config file found. You should run medoc --init.'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
if !@@config
|
|
73
|
+
# No alias
|
|
74
|
+
raise MedocError.new 'Error: no alias defined in config file. Visit https://github.com/acadet/medoc to know how to define aliases.'
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
if @@config.has_key? keyword
|
|
78
|
+
instructions = @@config[keyword]
|
|
79
|
+
target = ''
|
|
80
|
+
|
|
81
|
+
# Instructions can either be a simple directory
|
|
82
|
+
# or a list of aliases and directories
|
|
83
|
+
if instructions.kind_of? Array
|
|
84
|
+
instructions.each do |e|
|
|
85
|
+
if @@config.has_key?(e) && e != keyword
|
|
86
|
+
# Instruction is an existing alias
|
|
87
|
+
target = append target, Medoc.run(e)
|
|
88
|
+
else
|
|
89
|
+
# Simple directory
|
|
90
|
+
target = append target, e
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
else
|
|
94
|
+
# Only a directory
|
|
95
|
+
target = instructions
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
return target
|
|
99
|
+
else
|
|
100
|
+
raise MedocError.new "Error: no '#{keyword}' alias in config file."
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
private
|
|
105
|
+
|
|
106
|
+
###
|
|
107
|
+
# Appends a path to new dir
|
|
108
|
+
##
|
|
109
|
+
def self.append(path, dir)
|
|
110
|
+
if path.size > 0 && path[path.size - 1] != '/'
|
|
111
|
+
# Append '/' if missing
|
|
112
|
+
"#{path}/#{dir}"
|
|
113
|
+
else
|
|
114
|
+
"#{path}#{dir}"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
###
|
|
119
|
+
# Loads Medoc config file
|
|
120
|
+
##
|
|
121
|
+
def self.load_config
|
|
122
|
+
if !@@config.nil?
|
|
123
|
+
# File already loaded
|
|
124
|
+
return true
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Test if file exists
|
|
128
|
+
if !File.exists? @@config_file
|
|
129
|
+
return false
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
@@config = YAML.load_file @@config_file
|
|
133
|
+
true
|
|
134
|
+
end
|
|
135
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: medoc
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Adrien Cadet
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-01-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Medoc is a shell aliases manager. It lets you define shortcuts to jump
|
|
14
|
+
quickly to another directory.
|
|
15
|
+
email: acadet@live.fr
|
|
16
|
+
executables:
|
|
17
|
+
- medoc
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- README.md
|
|
22
|
+
- bin/medoc
|
|
23
|
+
- lib/medoc.rb
|
|
24
|
+
homepage: https://github.com/acadet/medoc
|
|
25
|
+
licenses: []
|
|
26
|
+
metadata: {}
|
|
27
|
+
post_install_message:
|
|
28
|
+
rdoc_options: []
|
|
29
|
+
require_paths:
|
|
30
|
+
- lib
|
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
32
|
+
requirements:
|
|
33
|
+
- - '>='
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '0'
|
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
requirements: []
|
|
42
|
+
rubyforge_project:
|
|
43
|
+
rubygems_version: 2.4.5
|
|
44
|
+
signing_key:
|
|
45
|
+
specification_version: 4
|
|
46
|
+
summary: Shell alias manager
|
|
47
|
+
test_files: []
|