am 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 852969fa27d5ac381cfbf936cdfa4fb066e65991
4
- data.tar.gz: 9ec05aebec06d777801b59c495b72a91cf967cce
3
+ metadata.gz: c3b038cb3f81b74b7abb30a9eb3afb59f6b10e48
4
+ data.tar.gz: 90814812b84e90359a4d273ebab2d54062527ec2
5
5
  SHA512:
6
- metadata.gz: 2a0275bb79a92fd03a219804b70c8f5326f42a7449617517fb71f9a39aa17d96f782f57cba55e66039beb6fb5df9037f4c4c34a5aace52d5ebc0743f63835bde
7
- data.tar.gz: bab4c2b8d9af19f0ea0c112d5df871d019850a6d3bccbde1287cef0e18525177794c76a2ed55f7385bc73c08931efda3a414f170b35993ff63c8c62a3e7fbaf2
6
+ metadata.gz: fb82b1d037927e39fa815c22bd1ce52ee2f2101066e552fa03518ef5fd799beae8d2ddf515dc25e41d6d9fb8ea42829d3c35d1e95aa1be3ad9a99eda6e26def5
7
+ data.tar.gz: 20f892204a581542dc3aa7f491da70e48dc52869579e68d5f7aacf4fe1cd936240bc472d22efd389f2bf1a9bbc8669d2cde1cd3adbd1600cb54b92754950480e
data/README.md CHANGED
@@ -57,7 +57,8 @@ echo 'source ~/.am_config' >> ~/.bash_profile
57
57
  * history file location(optional)
58
58
 
59
59
  ```
60
- # ~/.am_config
60
+ => ~/.am_local_config
61
+
61
62
  history_file=~/.custom_history
62
63
  ```
63
64
 
data/lib/am/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Am
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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
- ALIAS = 0
7
- COMMAND = 1
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
- File.open(CONFIG_FILE, 'r') do |file|
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 << line.gsub(/^alias /, '').strip.split('=', 2) if(line =~ /^alias/)
17
- @pg = Hash[*line.strip.split('=', 2)] if line =~ /^[^alias]/ && line =~ /^[^#.*]/
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
- tmp_file = CONFIG_FILE + '.tmp'
25
- file = File.open(tmp_file, "w")
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(tmp_file, CONFIG_FILE)
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
@@ -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" >> #{AM::CONFIG_FILE}`
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 eql(0)
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 eql(0)
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" >> #{AM::CONFIG_FILE}`
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::CONFIG_FILE}`
39
+ `echo "" > #{AM::LOCAL_FILE}`
40
40
  end
41
41
  end
42
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: am
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ka-yamashita