am 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/am/version.rb +1 -1
- data/lib/am.rb +4 -3
- data/lib/config.rb +22 -9
- data/lib/tail.rb +7 -0
- data/spec/lib/config_spec.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3b038cb3f81b74b7abb30a9eb3afb59f6b10e48
|
4
|
+
data.tar.gz: 90814812b84e90359a4d273ebab2d54062527ec2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb82b1d037927e39fa815c22bd1ce52ee2f2101066e552fa03518ef5fd799beae8d2ddf515dc25e41d6d9fb8ea42829d3c35d1e95aa1be3ad9a99eda6e26def5
|
7
|
+
data.tar.gz: 20f892204a581542dc3aa7f491da70e48dc52869579e68d5f7aacf4fe1cd936240bc472d22efd389f2bf1a9bbc8669d2cde1cd3adbd1600cb54b92754950480e
|
data/README.md
CHANGED
data/lib/am/version.rb
CHANGED
data/lib/am.rb
CHANGED
@@ -2,9 +2,10 @@ require "am/version"
|
|
2
2
|
require "am/cli"
|
3
3
|
module AM
|
4
4
|
|
5
|
-
CONFIG_FILE=File.expand_path('~/.am_config')
|
6
|
-
|
7
|
-
|
5
|
+
CONFIG_FILE = File.expand_path('~/.am_config')
|
6
|
+
LOCAL_FILE = File.expand_path('~/.am_local_config')
|
7
|
+
ALIAS = 0
|
8
|
+
COMMAND = 1
|
8
9
|
|
9
10
|
def self.p1(message="")
|
10
11
|
puts "\n#{message}"
|
data/lib/config.rb
CHANGED
@@ -8,21 +8,31 @@ module AM
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def file_load
|
11
|
-
@al
|
12
|
-
@pg
|
13
|
-
|
11
|
+
@al = []
|
12
|
+
@pg = {}
|
13
|
+
pg_buf = []
|
14
14
|
|
15
|
+
# load alias config
|
16
|
+
File.open(CONFIG_FILE, 'r') do |file|
|
15
17
|
file.each_line do |line|
|
16
|
-
@al
|
17
|
-
|
18
|
+
@al << line.gsub(/^alias /, '').strip.split('=', 2) if(line =~ /^alias/)
|
19
|
+
# migration
|
20
|
+
pg_buf << line.strip.split('=', 2) if line.strip =~ /^[^alias]/ && line.strip =~ /^[^#.*]/ && line.strip !~ /^$/
|
18
21
|
end
|
19
|
-
|
20
22
|
end if File.exists?(CONFIG_FILE)
|
23
|
+
|
24
|
+
# load program config
|
25
|
+
File.open(LOCAL_FILE, 'r') do |file|
|
26
|
+
file.each_line do |line|
|
27
|
+
pg_buf << line.strip.split('=', 2) if line.strip =~ /^[^alias]/ && line.strip =~ /^[^#.*]/ && line.strip !~ /^$/
|
28
|
+
end
|
29
|
+
end if File.exists?(LOCAL_FILE)
|
30
|
+
@pg = Hash[pg_buf] unless pg_buf.empty?
|
21
31
|
end
|
22
32
|
|
23
33
|
def save_config(exclude=nil)
|
24
|
-
|
25
|
-
file = File.open(
|
34
|
+
config_tmp_file = CONFIG_FILE + '.tmp'
|
35
|
+
file = File.open(config_tmp_file, "w")
|
26
36
|
new_al = []
|
27
37
|
|
28
38
|
file.puts("# alias config")
|
@@ -34,14 +44,17 @@ module AM
|
|
34
44
|
end
|
35
45
|
end
|
36
46
|
@al = new_al
|
47
|
+
file.close
|
37
48
|
|
49
|
+
local_tmp_file = LOCAL_FILE + '.tmp'
|
50
|
+
file = File.open(local_tmp_file, "w")
|
38
51
|
file.puts("\n# pg config")
|
39
52
|
@pg.each do |p,v|
|
40
53
|
r = "#{p.to_s}=#{v.to_s}"
|
41
54
|
file.puts(r)
|
42
55
|
end
|
43
56
|
file.close
|
44
|
-
File.rename(
|
57
|
+
(File.rename(config_tmp_file, CONFIG_FILE) == 0 && File.rename(local_tmp_file, LOCAL_FILE) == 0)
|
45
58
|
end
|
46
59
|
end
|
47
60
|
end
|
data/lib/tail.rb
CHANGED
@@ -28,7 +28,14 @@ module AM
|
|
28
28
|
puts "does not support is #{shell}"
|
29
29
|
exit
|
30
30
|
end
|
31
|
+
|
31
32
|
@profile[:file] = config.pg['history_file'] unless config.pg['history_file'].nil?
|
33
|
+
@profile[:file] = File.expand_path(@profile[:file])
|
34
|
+
|
35
|
+
unless File.exists?(@profile[:file])
|
36
|
+
puts "history file not found #{@profile[:file]}"
|
37
|
+
exit
|
38
|
+
end
|
32
39
|
end
|
33
40
|
|
34
41
|
def get_last_five_command
|
data/spec/lib/config_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe AM::Config do
|
|
4
4
|
context 'zsh' do
|
5
5
|
before do
|
6
6
|
`echo "alias test1='test az - AZ 09 _'" > #{AM::CONFIG_FILE}`
|
7
|
-
`echo "history_file=~/.zsh_history"
|
7
|
+
`echo "history_file=~/.zsh_history" > #{AM::LOCAL_FILE}`
|
8
8
|
@config= AM::Config.new
|
9
9
|
end
|
10
10
|
|
@@ -17,11 +17,11 @@ describe AM::Config do
|
|
17
17
|
it 'save config'do
|
18
18
|
# add
|
19
19
|
config = @config.al << ['test2', "'abcdefgeijklmn'"]
|
20
|
-
expect(@config.save_config).to
|
20
|
+
expect(@config.save_config).to be true
|
21
21
|
expect(@config.al.length).to eql(2)
|
22
22
|
|
23
23
|
# delete
|
24
|
-
expect(@config.save_config('test1')).to
|
24
|
+
expect(@config.save_config('test1')).to be true
|
25
25
|
expect(@config.al.length).to eql(1)
|
26
26
|
|
27
27
|
# valu check
|
@@ -33,10 +33,10 @@ describe AM::Config do
|
|
33
33
|
|
34
34
|
it 'pg config' do
|
35
35
|
# @config.pg_check
|
36
|
-
`echo "history_file=~/.csh_history"
|
36
|
+
`echo "history_file=~/.csh_history" > #{AM::LOCAL_FILE}`
|
37
37
|
config= AM::Config.new
|
38
38
|
expect(config.pg['history_file']).to eq "~/.csh_history"
|
39
|
-
`echo "" > #{AM::
|
39
|
+
`echo "" > #{AM::LOCAL_FILE}`
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|