mkalias 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -11
- data/bin/mkalias +48 -17
- data/lib/mkalias/version.rb +1 -1
- data/lib/mkalias.rb +30 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7141b7cc6b6bdfe69ebcd7bfc3a9daf28a3bff3e
|
4
|
+
data.tar.gz: fd583834b2ea509075c8c8f02b9c71657615da57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c6124af31a8ea0e14e6fe0f2e7151efbe8f4889709f16f9ab5a5ba4911bfa868221f84fdcc5b384587edf854293c56909a5a11fe2a88a33c56d4a75775772dd
|
7
|
+
data.tar.gz: 8214e02207f4b6bf8025717193a044e0a4f67906e8a55d1976999fa1d9155d8b695c4df05c626dc229d0966469a7fed1e7e726aadbe5e678c2f03ddae88d6af7
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Mkalias
|
1
|
+
# Mkalias [![Build Status](https://travis-ci.org/LucianoPC/mkalias.svg?branch=master)](https://travis-ci.org/LucianoPC/mkalias) [![Code Climate](https://codeclimate.com/github/LucianoPC/mkalias/badges/gpa.svg)](https://codeclimate.com/github/LucianoPC/mkalias) [![Gem Version](https://badge.fury.io/rb/mkalias.svg)](https://badge.fury.io/rb/mkalias)
|
2
2
|
|
3
3
|
MKalias is a gem to manage alias, when you can just add a command and you can
|
4
4
|
add a new alias, list the alias, show the alias command or remove the alias.
|
@@ -25,20 +25,28 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
options:
|
27
27
|
|
28
|
-
new
|
29
|
-
|
28
|
+
new $ mkalias new [alias] [command 1] [command 2] ... [command n]
|
29
|
+
- Create a new alias to run the commands
|
30
30
|
|
31
|
-
list
|
32
|
-
|
31
|
+
list $ mkalias list
|
32
|
+
- List all alias
|
33
33
|
|
34
|
-
show
|
35
|
-
|
34
|
+
show $ mkalias show
|
35
|
+
- Show commands of all alias
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
$ mkalias show [alias 1] [alias 2] ... [alias n]
|
38
|
+
- Show commands of the specified alias
|
39
39
|
|
40
|
-
remove
|
41
|
-
|
40
|
+
remove $ mkalias remove [alias 1] [alias 2] ... [alias n]
|
41
|
+
- Remove the specified alias
|
42
|
+
|
43
|
+
add_signal $ mkalias add_signal
|
44
|
+
- Add signal to run 'source ~/.bashrc' when
|
45
|
+
- add or remove an alias
|
46
|
+
|
47
|
+
remove_signal $ mkalias remove_signal"
|
48
|
+
- Remove signal to run 'source ~/.bashrc' when
|
49
|
+
- add or remove an alias
|
42
50
|
|
43
51
|
Attention: To make alias with args use #. Example:
|
44
52
|
$ mkalias new [alias] "echo #1 #2 #3"
|
data/bin/mkalias
CHANGED
@@ -3,7 +3,8 @@
|
|
3
3
|
require "bundler/setup"
|
4
4
|
require 'mkalias'
|
5
5
|
|
6
|
-
VALID_OPTIONS = ['new', 'list', 'show', 'remove'
|
6
|
+
VALID_OPTIONS = ['new', 'list', 'show', 'remove', 'add_signal',
|
7
|
+
'remove_signal']
|
7
8
|
|
8
9
|
def usage
|
9
10
|
puts "Usage: mkalias [option]"
|
@@ -26,13 +27,21 @@ def usage
|
|
26
27
|
puts " remove \t $ mkalias remove [alias 1] [alias 2] ... [alias n]"
|
27
28
|
puts "\t\t - Remove the specified alias"
|
28
29
|
puts ""
|
30
|
+
puts " add_signal \t $ mkalias add_signal"
|
31
|
+
puts "\t\t - Add signal to run 'source ~/.bashrc' when"
|
32
|
+
puts "\t\t - add or remove an alias"
|
33
|
+
puts ""
|
34
|
+
puts " remove_signal \t $ mkalias remove_signal"
|
35
|
+
puts "\t\t - Remove signal to run 'source ~/.bashrc' when"
|
36
|
+
puts "\t\t - add or remove an alias"
|
37
|
+
puts ""
|
29
38
|
puts "Attention: To make alias with args use #. Example:"
|
30
39
|
puts " $ mkalias new [alias] \"echo #1 #2 #3\""
|
31
40
|
puts " - Then you can use: $ [alias] arg1 arg2 arg3"
|
32
41
|
abort
|
33
42
|
end
|
34
43
|
|
35
|
-
def
|
44
|
+
def new
|
36
45
|
if ARGV.count < 3
|
37
46
|
usage
|
38
47
|
end
|
@@ -43,13 +52,13 @@ def new_alias
|
|
43
52
|
|
44
53
|
if result
|
45
54
|
puts " - Created Alias: #{alias_name}"
|
46
|
-
|
55
|
+
check_signal
|
47
56
|
else
|
48
57
|
puts " ERROR: O Alias [#{alias_name}] já existe"
|
49
58
|
end
|
50
59
|
end
|
51
60
|
|
52
|
-
def
|
61
|
+
def list
|
53
62
|
alias_names = Mkalias.list_alias
|
54
63
|
|
55
64
|
puts "Registered Alias:"
|
@@ -58,7 +67,7 @@ def list_alias
|
|
58
67
|
end
|
59
68
|
end
|
60
69
|
|
61
|
-
def
|
70
|
+
def show
|
62
71
|
if ARGV.count < 2
|
63
72
|
alias_names = Mkalias.list_alias
|
64
73
|
else
|
@@ -85,7 +94,7 @@ def show_alias
|
|
85
94
|
end
|
86
95
|
end
|
87
96
|
|
88
|
-
def
|
97
|
+
def remove
|
89
98
|
if ARGV.count < 2
|
90
99
|
usage
|
91
100
|
end
|
@@ -105,9 +114,41 @@ def remove_alias
|
|
105
114
|
removed_alias.each do |alias_name|
|
106
115
|
puts "- #{alias_name}"
|
107
116
|
end
|
117
|
+
|
118
|
+
check_signal
|
108
119
|
end
|
109
120
|
end
|
110
121
|
|
122
|
+
def add_signal
|
123
|
+
result = Mkalias.add_signal
|
124
|
+
|
125
|
+
if result
|
126
|
+
puts "Add signal to call 'source ~/.bashrc'"
|
127
|
+
puts " - Run '$ source ~/.bashrc' to update your bash"
|
128
|
+
else
|
129
|
+
puts "The signal has already been added"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def remove_signal
|
134
|
+
result = Mkalias.remove_signal
|
135
|
+
|
136
|
+
if result
|
137
|
+
puts "The signal was removed"
|
138
|
+
puts " - Run '$ source ~/.bashrc' to update your bash"
|
139
|
+
else
|
140
|
+
puts "The signal does not exist to be removed"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def check_signal
|
145
|
+
if Mkalias.has_signal?
|
146
|
+
`kill -USR1 #{Process.ppid}`
|
147
|
+
else
|
148
|
+
puts " - Run '$ source ~/.bashrc' to use your alias"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
111
152
|
def main
|
112
153
|
if ARGV.count == 0 || !VALID_OPTIONS.include?(ARGV[0])
|
113
154
|
usage
|
@@ -115,17 +156,7 @@ def main
|
|
115
156
|
|
116
157
|
option = ARGV[0]
|
117
158
|
|
118
|
-
|
119
|
-
new_alias
|
120
|
-
elsif option == 'list'
|
121
|
-
list_alias
|
122
|
-
elsif option == 'show'
|
123
|
-
show_alias
|
124
|
-
elsif option == 'remove'
|
125
|
-
remove_alias
|
126
|
-
else
|
127
|
-
usage
|
128
|
-
end
|
159
|
+
send("#{option}")
|
129
160
|
end
|
130
161
|
|
131
162
|
main
|
data/lib/mkalias/version.rb
CHANGED
data/lib/mkalias.rb
CHANGED
@@ -3,6 +3,7 @@ require 'set'
|
|
3
3
|
|
4
4
|
module Mkalias
|
5
5
|
|
6
|
+
SIGNAL_NAME = 'USR1'
|
6
7
|
BASHRC_PATH = "#{File.expand_path('~')}/.bashrc"
|
7
8
|
|
8
9
|
def self.new_alias(alias_name, commands, file_path=BASHRC_PATH)
|
@@ -10,7 +11,7 @@ module Mkalias
|
|
10
11
|
return false if alias_names.include?(alias_name)
|
11
12
|
|
12
13
|
commands = commands.join('; ') if commands.kind_of?(Array)
|
13
|
-
commands = commands.
|
14
|
+
commands = commands.tr('#', '$')
|
14
15
|
|
15
16
|
function_name = "mkalias_#{alias_name}"
|
16
17
|
bash_function = "function #{function_name}(){ #{commands}; }"
|
@@ -48,7 +49,7 @@ module Mkalias
|
|
48
49
|
file_path)
|
49
50
|
end
|
50
51
|
|
51
|
-
alias_commands.select!{ |
|
52
|
+
alias_commands.select!{ |_, value| !value.nil? }
|
52
53
|
return alias_commands
|
53
54
|
end
|
54
55
|
|
@@ -64,7 +65,33 @@ module Mkalias
|
|
64
65
|
return removed_alias
|
65
66
|
end
|
66
67
|
|
67
|
-
|
68
|
+
def self.add_signal(file_path=BASHRC_PATH)
|
69
|
+
return false if Mkalias.has_signal?(file_path)
|
70
|
+
|
71
|
+
trap_command = "trap 'source #{file_path}' #{SIGNAL_NAME}"
|
72
|
+
open(file_path, 'a') do |file|
|
73
|
+
file.puts("\n")
|
74
|
+
file.puts(trap_command)
|
75
|
+
end
|
76
|
+
|
77
|
+
true
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.remove_signal(file_path=BASHRC_PATH)
|
81
|
+
return false unless has_signal?(file_path)
|
82
|
+
|
83
|
+
trap_regex = /\btrap\s'source\s(.*)\sUSR1/
|
84
|
+
|
85
|
+
lines = File.readlines(file_path).reject{ |line| line =~ trap_regex }
|
86
|
+
File.open(file_path, "w"){ |f| lines.each { |line| f.puts line } }
|
87
|
+
|
88
|
+
true
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.has_signal?(file_path=BASHRC_PATH)
|
92
|
+
trap_regex = /\btrap\s'source\s(.*)\sUSR1/
|
93
|
+
!File.foreach(file_path).grep(trap_regex).empty?
|
94
|
+
end
|
68
95
|
|
69
96
|
def self.get_alias_command(alias_name, file_path=BASHRC_PATH)
|
70
97
|
alias_names = Mkalias.list_alias(file_path)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mkalias
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luciano Prestes Cavalcanti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|