am 0.0.7 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1c035e872c61d3c8de94e71e81b49d30fc26792
4
- data.tar.gz: 42f8fa57dad2dd410c302a59a1cb105b30773772
3
+ metadata.gz: 852969fa27d5ac381cfbf936cdfa4fb066e65991
4
+ data.tar.gz: 9ec05aebec06d777801b59c495b72a91cf967cce
5
5
  SHA512:
6
- metadata.gz: ebf1c71e6ccc74ef5ae1044c37bbead6ade425dfc4dafdd30ae637a21b6f852c4af53021d8453ce28da5da9aee7eac52bb07f7652e96e496aefad76554cc6240
7
- data.tar.gz: 83331d4c739e1a5f7dfdbc2296801741acbe481fd3687d7879ef1622d0c51907dce6288dbff90f33452ac888c399138f4afba218c149af0a019d041699f7f9de
6
+ metadata.gz: 2a0275bb79a92fd03a219804b70c8f5326f42a7449617517fb71f9a39aa17d96f782f57cba55e66039beb6fb5df9037f4c4c34a5aace52d5ebc0743f63835bde
7
+ data.tar.gz: bab4c2b8d9af19f0ea0c112d5df871d019850a6d3bccbde1287cef0e18525177794c76a2ed55f7385bc73c08931efda3a414f170b35993ff63c8c62a3e7fbaf2
data/README.md CHANGED
@@ -51,6 +51,17 @@ echo 'source ~/.am_config' >> ~/.bash_profile
51
51
 
52
52
  $ am del -l(list)
53
53
  delete alias select from current config
54
+
55
+ ### configure
56
+
57
+ * history file location(optional)
58
+
59
+ ```
60
+ # ~/.am_config
61
+ history_file=~/.custom_history
62
+ ```
63
+
64
+
54
65
  ## License
55
66
  * MIT
56
67
 
data/lib/am/cli.rb CHANGED
@@ -9,14 +9,13 @@ module AM
9
9
  default_command :show
10
10
  def initialize(*args)
11
11
  super
12
- config = Config.new
13
- @config = config.current
12
+ @config = Config.new
14
13
  @ui = Ui.new
15
14
  end
16
15
 
17
16
  desc "show", "show current alias"
18
17
  def show
19
- if @config.empty?
18
+ if @config.al.empty?
20
19
  puts 'a blank config'
21
20
  else
22
21
  @ui.print_current_config(@config)
@@ -26,7 +25,8 @@ module AM
26
25
  desc "add", "add alias"
27
26
  option :list, :type => :boolean, :aliases => '-l'
28
27
  def add
29
- tail = Tail.new
28
+ tail = Tail.new(@config)
29
+
30
30
  # registeration from history choice
31
31
  if options[:list]
32
32
  commands = tail.get_last_five_command
@@ -40,7 +40,7 @@ module AM
40
40
  end
41
41
 
42
42
  if uniq?(add_record) && valid?(add_record)
43
- @config << add_record
43
+ @config.al << add_record
44
44
  add_config(add_record)
45
45
  else
46
46
  AM.p1("")
@@ -52,7 +52,7 @@ module AM
52
52
  option :list, :type => :boolean, :aliases => '-l'
53
53
 
54
54
  def del(delete_alias=nil)
55
- if @config.empty?
55
+ if @config.al.empty?
56
56
  puts 'a blank config'
57
57
  exit
58
58
  end
@@ -67,27 +67,27 @@ module AM
67
67
  no_commands do
68
68
 
69
69
  def add_config(add_record)
70
- config = Config.new
71
- if config.save_config(@config)
70
+ if @config.save_config()
72
71
  AM.p1("[success] #{add_record[ALIAS]} / #{add_record[COMMAND]} added command")
73
72
  AM.p2("please run: [ source #{CONFIG_FILE} ]")
73
+
74
74
  else
75
75
  puts "[error] #{add_record[ALIAS]} / #{add_record[COMMAND]} couldn't add command"
76
76
  end
77
77
  end
78
78
 
79
79
  def delete_config(exclude)
80
- config = Config.new
81
- if config.save_config(@config, exclude)
80
+ if @config.save_config(exclude)
82
81
  AM.p1("[success] delete alias #{exclude}")
83
82
  AM.p2("please run: [ source #{CONFIG_FILE} ]")
83
+
84
84
  else
85
85
  AM.p2("[error] failue delete alias #{exclude}}")
86
86
  end
87
87
  end
88
88
 
89
89
  def uniq?(add_record)
90
- @config.each do |a,c|
90
+ @config.al.each do |a,c|
91
91
  if add_record[ALIAS] == a
92
92
  AM.p1("[error] not written as duplecate alias is '#{add_record[ALIAS]}'")
93
93
  return false
data/lib/am/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Am
2
- VERSION = "0.0.7"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/config.rb CHANGED
@@ -2,27 +2,44 @@ require 'am'
2
2
 
3
3
  module AM
4
4
  class Config
5
- def current
6
- config = []
5
+ attr_accessor :al, :pg
6
+ def initialize
7
+ file_load
8
+ end
9
+
10
+ def file_load
11
+ @al = []
12
+ @pg = {}
7
13
  File.open(CONFIG_FILE, 'r') do |file|
14
+
8
15
  file.each_line do |line|
9
- config << line.gsub(/^alias /, '').strip.split('=', 2)
16
+ @al << line.gsub(/^alias /, '').strip.split('=', 2) if(line =~ /^alias/)
17
+ @pg = Hash[*line.strip.split('=', 2)] if line =~ /^[^alias]/ && line =~ /^[^#.*]/
10
18
  end
19
+
11
20
  end if File.exists?(CONFIG_FILE)
12
- config
13
21
  end
14
22
 
15
- def save_config(config, exclude=nil)
23
+ def save_config(exclude=nil)
16
24
  tmp_file = CONFIG_FILE + '.tmp'
17
25
  file = File.open(tmp_file, "w")
26
+ new_al = []
18
27
 
19
- config.each do |a,c|
28
+ file.puts("# alias config")
29
+ @al.each do |a,c|
20
30
  r = "alias #{a.to_s}=#{c.to_s}"
21
31
  if a.to_s != exclude
22
32
  file.puts(r)
33
+ new_al << [a, c]
23
34
  end
24
35
  end
36
+ @al = new_al
25
37
 
38
+ file.puts("\n# pg config")
39
+ @pg.each do |p,v|
40
+ r = "#{p.to_s}=#{v.to_s}"
41
+ file.puts(r)
42
+ end
26
43
  file.close
27
44
  File.rename(tmp_file, CONFIG_FILE)
28
45
  end
data/lib/tail.rb CHANGED
@@ -2,32 +2,33 @@ require 'am'
2
2
 
3
3
  module AM
4
4
  class Tail
5
- def initialize(*args)
6
- set_profile
5
+ def initialize(config)
6
+ set_profile(config)
7
7
  end
8
8
 
9
- def set_profile
10
- shell = `echo $SHELL`
9
+ def set_profile(config)
10
+ shell = ENV['SHELL']
11
11
  @profile = {}
12
12
 
13
13
  if shell =~ /zsh/
14
14
  @profile = {
15
15
  pattern: '.*;(.*)',
16
- file: File.expand_path('~/.zsh_history'),
17
16
  margin: 0,
18
17
  max_line: 5,
18
+ file: '~/.zsh_history'
19
19
  }
20
20
  elsif shell =~ /bash/
21
21
  @profile = {
22
22
  pattern: '(.*)',
23
- file: File.expand_path('~/.bash_history'),
24
23
  margin: 1,
25
24
  max_line: 5,
25
+ file: '~/.bash_history'
26
26
  }
27
27
  else
28
28
  puts "does not support is #{shell}"
29
29
  exit
30
30
  end
31
+ @profile[:file] = config.pg['history_file'] unless config.pg['history_file'].nil?
31
32
  end
32
33
 
33
34
  def get_last_five_command
data/lib/ui.rb CHANGED
@@ -3,14 +3,14 @@ require 'am'
3
3
  module AM
4
4
  class Ui
5
5
  def print_current_config(config)
6
- aml = config.max_by{|c| c[0].length }[0].length #alias max length
7
- iml = config.length.to_s.length #index max length
6
+ aml = config.al.max_by{|c| c[0].length }[0].length #alias max length
7
+ iml = config.al.length.to_s.length #index max length
8
8
 
9
9
  AM::p1("current commands of the config")
10
- config.each_with_index do|r,i|
10
+ config.al.each_with_index do|r,i|
11
11
  # 1: name=command
12
12
  puts " #{' '*(iml - (i+1).to_s.length)}#{(i+1).to_s} : #{r[ALIAS].to_s}#{' '*(aml-r[ALIAS].length)} = #{r[COMMAND].to_s}"
13
- end unless config.empty?
13
+ end unless config.al.empty?
14
14
  AM::p1
15
15
  end
16
16
 
@@ -38,7 +38,7 @@ module AM
38
38
  print 'please input delete command number: '
39
39
  number = please_input
40
40
  valid?(number, '^[^0-9]', '[error] input using number!')
41
- delete_alias = config[number.to_i-1][ALIAS] if config.length >= number.to_i
41
+ delete_alias = config.al[number.to_i-1][ALIAS] if config.al.length >= number.to_i
42
42
  end
43
43
 
44
44
  def get_alias
@@ -1,29 +1,42 @@
1
1
  require 'spec_helper.rb'
2
2
 
3
3
  describe AM::Config do
4
- describe 'config commands tests' do
5
- before() do
6
- @config= AM::Config.new
4
+ context 'zsh' do
5
+ before do
7
6
  `echo "alias test1='test az - AZ 09 _'" > #{AM::CONFIG_FILE}`
7
+ `echo "history_file=~/.zsh_history" >> #{AM::CONFIG_FILE}`
8
+ @config= AM::Config.new
8
9
  end
10
+
9
11
  it 'load config' do
10
- @config.current
11
- expect(@config.current[0][0]).to eq 'test1'
12
- expect(@config.current[0][1]).to eq "'test az - AZ 09 _'"
12
+ expect(@config.al[0][0]).to eq 'test1'
13
+ expect(@config.al[0][1]).to eq "'test az - AZ 09 _'"
14
+ expect(@config.pg['history_file']).to eq "~/.zsh_history"
13
15
  end
16
+
14
17
  it 'save config'do
15
18
  # add
16
- config = @config.current << ['test2',"'abcdefgeijklmn'"]
17
- expect(@config.save_config(config)).to eql(0)
18
- expect(@config.current.length).to eql(2)
19
+ config = @config.al << ['test2', "'abcdefgeijklmn'"]
20
+ expect(@config.save_config).to eql(0)
21
+ expect(@config.al.length).to eql(2)
19
22
 
20
23
  # delete
21
- expect(@config.save_config(config,'test1')).to eql(0)
22
- expect(@config.current.length).to eql(1)
24
+ expect(@config.save_config('test1')).to eql(0)
25
+ expect(@config.al.length).to eql(1)
26
+
27
+ # valu check
28
+ expect(@config.al[0][0]).to eq 'test2'
29
+ expect(@config.al[0][1]).to eq "'abcdefgeijklmn'"
30
+ expect(@config.pg['history_file']).to eq "~/.zsh_history"
31
+
32
+ end
23
33
 
24
- # add check
25
- expect(@config.current[0][0]).to eq 'test2'
26
- expect(@config.current[0][1]).to eq "'abcdefgeijklmn'"
34
+ it 'pg config' do
35
+ # @config.pg_check
36
+ `echo "history_file=~/.csh_history" >> #{AM::CONFIG_FILE}`
37
+ config= AM::Config.new
38
+ expect(config.pg['history_file']).to eq "~/.csh_history"
39
+ `echo "" > #{AM::CONFIG_FILE}`
27
40
  end
28
41
  end
29
42
  end
@@ -1,20 +1,36 @@
1
1
  require 'spec_helper.rb'
2
2
 
3
3
  describe AM::Tail do
4
- describe 'tail commands tests' do
4
+ context 'tail commands tests' do
5
+ shared_examples_for "shell test" do
6
+ before do
7
+ config= AM::Config.new
8
+ config.pg['history_file'] = hist_file
9
+ ENV['SHELL'] = shell
10
+ @tail = AM::Tail.new(config)
11
+ end
5
12
 
6
- before() do
7
- @tail = AM::Tail.new
13
+ it 'get_last_five_commands' do
14
+ expect(@tail.get_last_five_command.length).to eq 5
15
+ expect(@tail.get_last_five_command[0]).to match(/[a-z]+/)
16
+ end
17
+
18
+ it 'get_last_command' do
19
+ expect(@tail.get_last_command.length).to be >= 1
20
+ expect(@tail.get_last_command[0]).to match(/[a-z]+/)
21
+ end
8
22
  end
9
23
 
10
- it 'print_last_commands' do
11
- expect(@tail.get_last_five_command.length).to eq 5
12
- expect(@tail.get_last_five_command[0]).to match(/[a-z]+/)
24
+ describe 'zsh' do
25
+ let(:hist_file) { '~/.zsh_history' }
26
+ let(:shell) {'/bin/zsh' }
27
+ it_should_behave_like 'shell test'
13
28
  end
14
29
 
15
- it 'get_last_command' do
16
- expect(@tail.get_last_command.length).to be >= 1
17
- expect(@tail.get_last_command[0]).to match(/[a-z]+/)
30
+ describe 'bash' do
31
+ let(:hist_file) { '~/.bash_history' }
32
+ let(:shell) {'/bin/bash' }
33
+ it_should_behave_like 'shell test'
18
34
  end
19
35
  end
20
36
  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.0.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ka-yamashita