mkalias 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/mkalias/version.rb +1 -1
- data/lib/mkalias.rb +30 -21
- 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: 1948f9aa0438885fe26d111aff8ffc7b97ab1f6e
|
4
|
+
data.tar.gz: cacd144cb21b36258d1e129b3da46c560ee2e442
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d97cd21536fb5a1d58533ff7c6ae14cf93ba5a87745c545ca1a92da0e1de667f1cf6f2f5e7f6a5add46df4c69e925589831a6072fa6c064a2c29d9879963d0a3
|
7
|
+
data.tar.gz: 42b5d41f02465b52790105b2012d1257e3f0ad1d19b57c0d8b7500ce00eab5e2cce4a17c9da1de10e5e23172fece86d6fcc0468a849f132e41b2aff8c3293e58
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
run: $ mkalias [option]
|
25
25
|
|
26
|
-
|
26
|
+
options:
|
27
27
|
|
28
28
|
new $ mkalias new [alias] [command 1] [command 2] ... [command n]
|
29
29
|
- Create a new alias to run the commands
|
@@ -40,17 +40,17 @@ Or install it yourself as:
|
|
40
40
|
remove $ mkalias remove [alias 1] [alias 2] ... [alias n]
|
41
41
|
- Remove the specified alias
|
42
42
|
|
43
|
-
|
43
|
+
add_signal $ mkalias add_signal
|
44
44
|
- Add signal to run 'source ~/.bashrc' when
|
45
45
|
- add or remove an alias
|
46
46
|
|
47
|
-
|
47
|
+
remove_signal $ mkalias remove_signal"
|
48
48
|
- Remove signal to run 'source ~/.bashrc' when
|
49
49
|
- add or remove an alias
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
Attention: To make alias with args use #. Example:
|
52
|
+
$ mkalias new [alias] "echo #1 #2 #3"
|
53
|
+
Then you can use: $ [alias] arg1 arg2 arg3
|
54
54
|
|
55
55
|
|
56
56
|
## Development
|
data/lib/mkalias/version.rb
CHANGED
data/lib/mkalias.rb
CHANGED
@@ -3,15 +3,14 @@ require 'set'
|
|
3
3
|
|
4
4
|
module Mkalias
|
5
5
|
|
6
|
-
|
6
|
+
SIGNAL_NAME = 'USR1'
|
7
7
|
BASHRC_PATH = "#{File.expand_path('~')}/.bashrc"
|
8
8
|
|
9
9
|
def self.new_alias(alias_name, commands, file_path=BASHRC_PATH)
|
10
10
|
alias_names = Mkalias.list_alias(file_path)
|
11
11
|
return false if alias_names.include?(alias_name)
|
12
12
|
|
13
|
-
commands =
|
14
|
-
commands = commands.tr('#', '$')
|
13
|
+
commands = Mkalias.prepare_commands(commands)
|
15
14
|
|
16
15
|
function_name = "mkalias_#{alias_name}"
|
17
16
|
bash_function = "function #{function_name}(){ #{commands}; }"
|
@@ -23,7 +22,7 @@ module Mkalias
|
|
23
22
|
file.puts(bash_function)
|
24
23
|
end
|
25
24
|
|
26
|
-
true
|
25
|
+
return true
|
27
26
|
end
|
28
27
|
|
29
28
|
def self.list_alias(file_path=BASHRC_PATH)
|
@@ -50,7 +49,7 @@ module Mkalias
|
|
50
49
|
end
|
51
50
|
|
52
51
|
alias_commands.select!{ |_, value| !value.nil? }
|
53
|
-
|
52
|
+
alias_commands
|
54
53
|
end
|
55
54
|
|
56
55
|
def self.remove_alias(alias_names, file_path=BASHRC_PATH)
|
@@ -62,36 +61,36 @@ module Mkalias
|
|
62
61
|
removed_alias << alias_name if removed
|
63
62
|
end
|
64
63
|
|
65
|
-
|
64
|
+
removed_alias
|
66
65
|
end
|
67
66
|
|
68
|
-
|
69
|
-
|
67
|
+
def self.add_signal(file_path=BASHRC_PATH)
|
68
|
+
return false if Mkalias.has_signal?(file_path)
|
70
69
|
|
71
|
-
|
70
|
+
trap_command = "trap 'source #{file_path}' #{SIGNAL_NAME}"
|
72
71
|
open(file_path, 'a') do |file|
|
73
72
|
file.puts("\n")
|
74
73
|
file.puts(trap_command)
|
75
74
|
end
|
76
75
|
|
77
|
-
|
78
|
-
|
76
|
+
return true
|
77
|
+
end
|
79
78
|
|
80
|
-
|
81
|
-
|
79
|
+
def self.remove_signal(file_path=BASHRC_PATH)
|
80
|
+
return false unless has_signal?(file_path)
|
82
81
|
|
83
|
-
|
82
|
+
trap_regex = /\btrap\s'source\s(.*)\sUSR1/
|
84
83
|
|
85
84
|
lines = File.readlines(file_path).reject{ |line| line =~ trap_regex }
|
86
85
|
File.open(file_path, "w"){ |f| lines.each { |line| f.puts line } }
|
87
86
|
|
88
|
-
|
89
|
-
|
87
|
+
return true
|
88
|
+
end
|
90
89
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
90
|
+
def self.has_signal?(file_path=BASHRC_PATH)
|
91
|
+
trap_regex = /\btrap\s'source\s(.*)\sUSR1/
|
92
|
+
!File.foreach(file_path).grep(trap_regex).empty?
|
93
|
+
end
|
95
94
|
|
96
95
|
def self.get_alias_command(alias_name, file_path=BASHRC_PATH)
|
97
96
|
alias_names = Mkalias.list_alias(file_path)
|
@@ -107,7 +106,7 @@ module Mkalias
|
|
107
106
|
return result.captures.first.split(';').each{ |c| c.strip! } if result
|
108
107
|
end
|
109
108
|
|
110
|
-
nil
|
109
|
+
return nil
|
111
110
|
end
|
112
111
|
|
113
112
|
def self.remove_one_alias(alias_name, file_path=BASHRC_PATH)
|
@@ -122,4 +121,14 @@ module Mkalias
|
|
122
121
|
|
123
122
|
return true
|
124
123
|
end
|
124
|
+
|
125
|
+
def self.prepare_commands(commands)
|
126
|
+
commands = commands.join('; ') if commands.kind_of?(Array)
|
127
|
+
unless commands.include?(';') or commands.include?('#')
|
128
|
+
commands = "#{commands} $@"
|
129
|
+
end
|
130
|
+
commands = commands.tr('#', '$')
|
131
|
+
|
132
|
+
commands
|
133
|
+
end
|
125
134
|
end
|
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.4
|
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-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|