am 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/am/cli.rb +22 -32
- data/lib/am/version.rb +1 -1
- data/lib/am.rb +3 -10
- data/lib/config.rb +5 -8
- data/lib/message_control.rb +28 -15
- data/lib/tail.rb +24 -30
- data/lib/ui.rb +46 -30
- data/lib/validate.rb +5 -11
- data/spec/lib/am/cli_spec.rb +10 -35
- data/spec/lib/tail_spec.rb +3 -7
- data/spec/spec_helper.rb +20 -11
- 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: 315f5f6dd4042ccb59e3857fbdaf45963aa322b3
|
4
|
+
data.tar.gz: 1c91d2a92c83210ded459f4b0f86a6f4aef340ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc38956ce7f0e3c1265c13bbf8ed64da4700266e0c72fa96d9b7b2f6d9f63b71dbdff05621dc7d34604f383af2f62c7a8b00f369991ed4e0f842b152fcdd5f42
|
7
|
+
data.tar.gz: 11c2ad7c640b968e598d1e4c76379add8b5f6cd0b10494e81eb660571a4ae4cd194d65286b83071086178ceadbf8c205f0708f76f7297169810dfcca9e266d3d
|
data/README.md
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
## Usage
|
12
12
|
|
13
13
|
* zsh user
|
14
|
+
|
14
15
|
run this command
|
15
16
|
```
|
16
17
|
echo 'source ~/.am_config' >> ~/.zprofile
|
@@ -31,7 +32,7 @@ shopt -u histappend
|
|
31
32
|
export HISTSIZE=9999
|
32
33
|
```
|
33
34
|
|
34
|
-
run this
|
35
|
+
run this command
|
35
36
|
|
36
37
|
```
|
37
38
|
echo 'source ~/.am_config' >> ~/.bash_profile
|
@@ -55,7 +56,7 @@ echo 'source ~/.am_config' >> ~/.bash_profile
|
|
55
56
|
delete alias select from current config
|
56
57
|
|
57
58
|
### configure
|
58
|
-
*
|
59
|
+
* default alias
|
59
60
|
```
|
60
61
|
aml = source ~/.am_config
|
61
62
|
```
|
data/lib/am/cli.rb
CHANGED
@@ -18,6 +18,7 @@ module AM
|
|
18
18
|
super
|
19
19
|
@config = Config.new
|
20
20
|
@ui = Ui.new
|
21
|
+
@tail = Tail.new(@config)
|
21
22
|
end
|
22
23
|
|
23
24
|
desc "show", "show current alias"
|
@@ -30,50 +31,39 @@ module AM
|
|
30
31
|
end
|
31
32
|
|
32
33
|
desc "add", "add alias"
|
33
|
-
option :list, :type => :boolean, :aliases => '-l'
|
34
34
|
def add
|
35
|
-
|
35
|
+
commands = @tail.get_last_command
|
36
36
|
|
37
|
-
|
38
|
-
if options[:list]
|
39
|
-
commands = tail.get_last_five_command
|
40
|
-
@ui.print_last_commands(commands)
|
41
|
-
new_alias = @ui.add_command_with_number(commands)
|
37
|
+
error(:not_exists_history_record) if commands.nil?
|
42
38
|
|
43
|
-
|
44
|
-
|
45
|
-
last_command = tail.get_last_command
|
46
|
-
new_alias = @ui.add_command_with_last_history(last_command)
|
47
|
-
end
|
39
|
+
@ui.print_last_commands(commands)
|
40
|
+
new_alias = @ui.add_command_with_number(commands)
|
48
41
|
|
49
|
-
|
50
|
-
|
42
|
+
unless new_alias
|
43
|
+
add
|
44
|
+
else
|
45
|
+
if uniq?(new_alias)
|
46
|
+
@config.add_config(new_alias)
|
47
|
+
end
|
51
48
|
end
|
52
49
|
end
|
53
50
|
|
54
51
|
desc "del", "delete alias"
|
55
|
-
|
56
|
-
|
57
|
-
if @config.al.empty?
|
58
|
-
notice(:config_empty)
|
59
|
-
exit
|
60
|
-
end
|
61
|
-
|
62
|
-
if options[:list] || delete_alias == nil
|
63
|
-
# convert array
|
52
|
+
def del
|
53
|
+
unless @config.al.empty?
|
64
54
|
arr = @ui.print_current_config(@config)
|
65
55
|
delete_alias = @ui.del_command_with_number(arr)
|
66
|
-
|
67
|
-
|
68
|
-
|
56
|
+
|
57
|
+
if delete_alias && @config.al.key?(delete_alias)
|
58
|
+
@config.al.delete(delete_alias)
|
59
|
+
@config.delete_config(delete_alias)
|
60
|
+
else
|
61
|
+
warning(:empty_config_number)
|
62
|
+
del
|
63
|
+
end
|
69
64
|
else
|
70
|
-
|
71
|
-
self.del
|
65
|
+
notice(:config_empty)
|
72
66
|
end
|
73
|
-
@config.delete_config(delete_alias)
|
74
|
-
end
|
75
|
-
|
76
|
-
no_commands do
|
77
67
|
end
|
78
68
|
end
|
79
69
|
end
|
data/lib/am/version.rb
CHANGED
data/lib/am.rb
CHANGED
@@ -1,18 +1,11 @@
|
|
1
|
-
# encoding: utf-8
|
1
|
+
# encoding: utf-8
|
2
2
|
require "am/version"
|
3
3
|
require "am/cli"
|
4
|
-
module AM
|
4
|
+
module AM
|
5
5
|
|
6
6
|
CONFIG_FILE = File.expand_path('~/.am_config')
|
7
7
|
LOCAL_FILE = File.expand_path('~/.am_local_config')
|
8
8
|
ALIAS = 0
|
9
9
|
COMMAND = 1
|
10
|
-
|
11
|
-
def self.p1(message="")
|
12
|
-
puts "\n#{message}"
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.p2(message="")
|
16
|
-
puts "#{message}\n\n"
|
17
|
-
end
|
10
|
+
TAIL_LINE = 10
|
18
11
|
end
|
data/lib/config.rb
CHANGED
@@ -14,7 +14,7 @@ module AM
|
|
14
14
|
def load_config
|
15
15
|
@al = file_load(CONFIG_FILE)
|
16
16
|
@pg = file_load(LOCAL_FILE)
|
17
|
-
@al.delete('aml')
|
17
|
+
@al.delete('aml') #delete default alias
|
18
18
|
end
|
19
19
|
|
20
20
|
def add_config(new_alias)
|
@@ -22,7 +22,7 @@ module AM
|
|
22
22
|
if save_config
|
23
23
|
notice(:success_add_command, [new_alias.first.to_a, CONFIG_FILE].flatten)
|
24
24
|
else
|
25
|
-
error(
|
25
|
+
error(:add_command_fail,new_alias.flatten)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -31,14 +31,12 @@ module AM
|
|
31
31
|
if save_config
|
32
32
|
notice(:success_delete_command, [del_alias, CONFIG_FILE])
|
33
33
|
else
|
34
|
-
error(:
|
34
|
+
error(:delete_command_fail, del_alias)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def save_config
|
39
|
-
(
|
40
|
-
file_write(CONFIG_FILE, @al.merge({"aml" => "'source ~/.am_config'"}))
|
41
|
-
)
|
39
|
+
(file_write(CONFIG_FILE, @al.merge({"aml" => "'source ~/.am_config'"})))
|
42
40
|
end
|
43
41
|
|
44
42
|
def file_write(file_name, config)
|
@@ -49,9 +47,8 @@ module AM
|
|
49
47
|
r = "alias #{k.to_s}=#{v.to_s}"
|
50
48
|
file.puts(r)
|
51
49
|
end
|
52
|
-
|
53
50
|
file.close
|
54
|
-
|
51
|
+
File.rename(tmp_file, file_name) == 0
|
55
52
|
end
|
56
53
|
|
57
54
|
def file_load(file_name)
|
data/lib/message_control.rb
CHANGED
@@ -5,41 +5,54 @@ module AM
|
|
5
5
|
module MessageControl
|
6
6
|
NOTICE_MESSAGE = {
|
7
7
|
config_empty: 'config is empty',
|
8
|
-
success_add_command: "success! %s / %s added command\n please run: [ source %s ]",
|
8
|
+
success_add_command: "success! %s / %s added command\n please run: [ aml ] or [ source %s ]",
|
9
9
|
success_delete_command: "success! %s delete alias\n please run: [ source %s ]"
|
10
10
|
}
|
11
11
|
WARNING_MESSAGE = {
|
12
12
|
add_command: "%s / %s couldn't add command",
|
13
13
|
empty_config_number: "selected number missing in current config",
|
14
|
-
|
15
|
-
|
14
|
+
validate_number: "please input using number",
|
15
|
+
validate_number_range: "please input number 1-%s",
|
16
|
+
validate_alias: 'input using a-z or 0-9 or _ or -',
|
16
17
|
}
|
17
18
|
ERROR_MESSAGE = {
|
18
|
-
|
19
|
+
add_command_fail: "%s / %s couldn't add command",
|
19
20
|
validate_length_zero: "%s / %s length equal 0",
|
20
|
-
|
21
|
+
delete_command_fail: "fail delete alias %s",
|
22
|
+
duplicate_alias: "duplicate alias is '%s'",
|
23
|
+
duplicate_command: "duplicate command is %s",
|
24
|
+
no_support: "does not support is %s",
|
25
|
+
not_exists_history_file: "history file not found %s",
|
26
|
+
not_exists_history_record: "history record not exists"
|
21
27
|
}
|
22
28
|
|
23
29
|
def notice(code, val=nil)
|
24
|
-
|
25
|
-
print(NOTICE_MESSAGE, 'info', code, val)
|
26
|
-
puts '-'*60
|
30
|
+
print_message(NOTICE_MESSAGE, 'info', code, val)
|
27
31
|
end
|
28
32
|
|
29
33
|
def warning(code, val=nil)
|
30
|
-
|
31
|
-
print(WARNING_MESSAGE, 'warning', code, val)
|
32
|
-
puts '-'*60
|
34
|
+
print_message(WARNING_MESSAGE, 'warning', code, val)
|
33
35
|
end
|
34
36
|
def error(code, val=nil)
|
35
|
-
|
36
|
-
print(ERROR_MESSAGE, 'error', code, val)
|
37
|
-
puts '-'*60
|
37
|
+
print_message(ERROR_MESSAGE, 'error', code, val)
|
38
38
|
exit
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
41
|
+
def print_message(template, prefix, code, val=nil)
|
42
|
+
before_sepalate
|
42
43
|
puts "[#{prefix}] #{template[code]}"%val
|
44
|
+
after_sepalate
|
43
45
|
end
|
46
|
+
|
47
|
+
def before_sepalate
|
48
|
+
puts ''
|
49
|
+
puts '-'*60
|
50
|
+
end
|
51
|
+
|
52
|
+
def after_sepalate
|
53
|
+
puts '-'*60
|
54
|
+
puts ''
|
55
|
+
end
|
56
|
+
|
44
57
|
end
|
45
58
|
end
|
data/lib/tail.rb
CHANGED
@@ -1,66 +1,60 @@
|
|
1
|
-
# encoding: utf-8
|
1
|
+
# encoding: utf-8
|
2
2
|
require 'am'
|
3
|
+
require 'message_control'
|
3
4
|
|
4
5
|
module AM
|
5
6
|
class Tail
|
7
|
+
include MessageControl
|
6
8
|
attr_accessor :profile
|
9
|
+
|
7
10
|
def initialize(config)
|
8
11
|
@profile = get_profile(config)
|
9
12
|
end
|
10
13
|
|
11
14
|
def get_profile(config)
|
12
15
|
shell = ENV['SHELL']
|
13
|
-
|
14
|
-
when /zsh/ then set_hash(0,
|
15
|
-
when /bash/ then set_hash(1,
|
16
|
-
else
|
17
|
-
|
18
|
-
exit
|
16
|
+
profile = case shell
|
17
|
+
when /zsh/ then set_hash(0, '~/.zsh_history')
|
18
|
+
when /bash/ then set_hash(1, '~/.bash_history')
|
19
|
+
else
|
20
|
+
error(:no_support, shell)
|
19
21
|
end
|
22
|
+
f = config.pg['history_file']
|
23
|
+
profile[:file] = f if f
|
24
|
+
profile[:file] = File.expand_path(profile[:file])
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
unless File.exists?(h[:file])
|
25
|
-
#todo raise
|
26
|
-
puts "history file not found #{h[:file]}"
|
26
|
+
unless File.exists?(profile[:file])
|
27
|
+
error(:not_exists_history_file, profile[:file])
|
27
28
|
exit
|
28
29
|
end
|
29
|
-
|
30
|
+
profile
|
30
31
|
end
|
31
32
|
|
32
|
-
def set_hash(margin,
|
33
|
-
return { margin: margin,
|
33
|
+
def set_hash(margin, history_file)
|
34
|
+
return { margin: margin, file: history_file }
|
34
35
|
end
|
35
36
|
|
36
|
-
def
|
37
|
+
def get_last_command
|
37
38
|
commands = []
|
38
|
-
|
39
|
-
last_commands = `tail -#{@profile[:max_line] + 1 - @profile[:margin]} #{@profile[:file]} | head -#{@profile[:max_line]}`.split("\n")
|
39
|
+
last_commands = `tail -#{TAIL_LINE + 1 - @profile[:margin]} #{@profile[:file]} | head -#{TAIL_LINE}`.split("\n")
|
40
40
|
unless last_commands.empty?
|
41
41
|
last_commands.each_with_index do |c,i|
|
42
|
-
|
42
|
+
r = sampling(c)
|
43
|
+
commands << r if r
|
43
44
|
end
|
44
45
|
commands
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
def get_last_command
|
49
|
-
r=""
|
50
|
-
if c = `tail -#{2-@profile[:margin]} #{@profile[:file]} | head -1`
|
51
|
-
sampling(c)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
49
|
def sampling(command)
|
56
50
|
zsh = '[0-9]+:[0-0];(.*)'
|
57
51
|
bash = '(.*)'
|
58
52
|
if command =~ /#{zsh}/
|
59
|
-
|
53
|
+
pattern = zsh
|
60
54
|
else
|
61
|
-
|
55
|
+
pattern = bash
|
62
56
|
end
|
63
|
-
command.split(/#{
|
57
|
+
command.split(/#{pattern}/)[COMMAND].strip if command.strip !~ /^$/
|
64
58
|
end
|
65
59
|
end
|
66
60
|
end
|
data/lib/ui.rb
CHANGED
@@ -1,65 +1,81 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'am'
|
3
|
+
require 'validate'
|
3
4
|
|
4
5
|
module AM
|
5
6
|
class Ui
|
7
|
+
include MessageControl
|
8
|
+
include Validate
|
9
|
+
|
6
10
|
def print_current_config(config)
|
7
11
|
aml = config.al.max_by{|c| c[0].length }[0].length #alias max length
|
8
12
|
iml = config.al.length.to_s.length #index max length
|
9
13
|
arr = [] #use delete number
|
10
|
-
|
14
|
+
|
15
|
+
before_sepalate
|
16
|
+
puts 'current registered alias'
|
11
17
|
config.al.each_with_index do|(k,v),i|
|
12
18
|
# 1: name=command
|
13
19
|
puts " #{' '*(iml - (i+1).to_s.length)}#{(i+1).to_s} : #{k.to_s}#{' '*(aml-k.length)} = #{v.to_s}"
|
14
20
|
arr << [i,k]
|
15
|
-
end
|
16
|
-
|
21
|
+
end
|
22
|
+
after_sepalate
|
17
23
|
arr
|
18
24
|
end
|
19
25
|
|
20
26
|
def print_last_commands(commands)
|
27
|
+
iml = commands.length.to_s.length #index max length
|
28
|
+
|
29
|
+
before_sepalate
|
30
|
+
puts 'current history commands'
|
21
31
|
commands.each_with_index do |c,i|
|
22
|
-
puts " #{(i+1).to_s} : #{c.to_s}"
|
23
|
-
end
|
32
|
+
puts " #{' '*(iml - (i+1).to_s.length)}#{(i+1).to_s} : #{c.to_s}"
|
33
|
+
end
|
34
|
+
after_sepalate
|
24
35
|
end
|
25
36
|
|
26
37
|
def add_command_with_number(commands)
|
27
|
-
|
28
|
-
|
29
|
-
valid?(number,
|
30
|
-
|
31
|
-
|
32
|
-
|
38
|
+
number = get_number
|
39
|
+
|
40
|
+
if valid?(number, "^[^0-9]+$")
|
41
|
+
warning(:validate_number)
|
42
|
+
elsif number.to_i > TAIL_LINE || number.to_i <= 0
|
43
|
+
warning(:validate_number_range, TAIL_LINE)
|
44
|
+
else
|
45
|
+
alias_name = get_alias
|
46
|
+
{alias_name => quot(commands[number.to_i-1].strip)}
|
47
|
+
end
|
33
48
|
|
34
|
-
def add_command_with_last_history(command)
|
35
|
-
puts "add command is #{quot(command.strip)}"
|
36
|
-
alias_name = get_alias
|
37
|
-
{alias_name => quot(command)}
|
38
49
|
end
|
39
50
|
|
40
51
|
def del_command_with_number(arr)
|
41
|
-
|
42
|
-
|
43
|
-
valid?(number,
|
44
|
-
|
45
|
-
|
52
|
+
number = get_number
|
53
|
+
|
54
|
+
if valid?(number, "^[1-9]+$")
|
55
|
+
arr[number.to_i-1][1] if arr.length >= number.to_i
|
56
|
+
else
|
57
|
+
warning(:validate_number)
|
58
|
+
end
|
46
59
|
end
|
47
60
|
|
48
|
-
def
|
49
|
-
print
|
50
|
-
|
51
|
-
valid?(name, '[^\w-]', '[error] input using a-z or 0-9 or _ or -')
|
52
|
-
name.strip
|
61
|
+
def get_number
|
62
|
+
print 'please select number: '
|
63
|
+
get_stdin
|
53
64
|
end
|
54
65
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
|
66
|
+
def get_alias
|
67
|
+
print "please input command alias name: "
|
68
|
+
alias_name = get_stdin
|
69
|
+
if valid?(alias_name, '^[\w-]+$')
|
70
|
+
alias_name.strip
|
71
|
+
else
|
72
|
+
warning(:validate_alias)
|
73
|
+
get_alias
|
59
74
|
end
|
60
75
|
end
|
61
76
|
|
62
|
-
|
77
|
+
|
78
|
+
def get_stdin
|
63
79
|
while val = STDIN.gets
|
64
80
|
break if /\n$/ =~ val
|
65
81
|
end
|
data/lib/validate.rb
CHANGED
@@ -3,27 +3,21 @@ require 'am'
|
|
3
3
|
|
4
4
|
module AM
|
5
5
|
module Validate
|
6
|
+
include MessageControl
|
6
7
|
def uniq?(new_alias)
|
7
8
|
ak,av = new_alias.first
|
8
9
|
@config.al.each do |k,v|
|
9
10
|
if ak == k
|
10
|
-
|
11
|
-
return false
|
11
|
+
error(:duplicate_alias, ak)
|
12
12
|
elsif av == v
|
13
|
-
|
14
|
-
return false
|
13
|
+
error(:duplicate_command, av)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
true
|
18
17
|
end
|
19
18
|
|
20
|
-
def valid?(
|
21
|
-
|
22
|
-
unless ak.length > 0 || av.length > 0 || ak == 'aml'
|
23
|
-
error(:validate_lenght_zero, [ak,av])
|
24
|
-
end
|
25
|
-
true
|
19
|
+
def valid?(val, pattern)
|
20
|
+
/#{pattern}/ =~ val && val.to_s.length != 0
|
26
21
|
end
|
27
|
-
|
28
22
|
end
|
29
23
|
end
|
data/spec/lib/am/cli_spec.rb
CHANGED
@@ -3,11 +3,6 @@ require 'spec_helper.rb'
|
|
3
3
|
|
4
4
|
describe AM::CLI do
|
5
5
|
shared_examples_for "shell test" do
|
6
|
-
before do
|
7
|
-
ENV['SHELL'] = shell
|
8
|
-
add_history
|
9
|
-
end
|
10
|
-
|
11
6
|
before(:each) do
|
12
7
|
add_alias_config
|
13
8
|
@cli = AM::CLI.new
|
@@ -19,29 +14,6 @@ describe AM::CLI do
|
|
19
14
|
end
|
20
15
|
end
|
21
16
|
|
22
|
-
describe 'register' do
|
23
|
-
describe 'add' do
|
24
|
-
before do
|
25
|
-
allow(STDIN).to receive(:gets) { "add_command_alias\n" }
|
26
|
-
expect { @cli.show }.not_to output(/add_command_alias/).to_stdout
|
27
|
-
end
|
28
|
-
it 'single' do
|
29
|
-
expect { @cli.add }.to output(/success/).to_stdout
|
30
|
-
expect { @cli.add }.to output(/duplecate/).to_stdout
|
31
|
-
expect { @cli.show }.to output(/add_command_alias/).to_stdout
|
32
|
-
end
|
33
|
-
end
|
34
|
-
describe 'delete' do
|
35
|
-
before do
|
36
|
-
expect { @cli.show }.to output(/ほげ/).to_stdout
|
37
|
-
end
|
38
|
-
it 'single' do
|
39
|
-
expect { @cli.del('ほげ') }.to output(/success/).to_stdout
|
40
|
-
expect { @cli.show }.not_to output(/ほげ/).to_stdout
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
17
|
describe 'register option' do
|
46
18
|
describe 'add' do
|
47
19
|
before do
|
@@ -49,10 +21,9 @@ describe AM::CLI do
|
|
49
21
|
expect { @cli.show }.to_not output(/last_command_alias/).to_stdout
|
50
22
|
end
|
51
23
|
it 'list' do
|
52
|
-
expect { @cli.
|
53
|
-
expect {
|
24
|
+
expect { @cli.add }.to output(/#{match_last_command}/).to_stdout
|
25
|
+
expect { @cli.show }.to output(/last_command_alias/).to_stdout
|
54
26
|
end
|
55
|
-
|
56
27
|
end
|
57
28
|
describe 'del' do
|
58
29
|
before do
|
@@ -60,19 +31,23 @@ describe AM::CLI do
|
|
60
31
|
expect { @cli.show }.to output(/hoge/).to_stdout
|
61
32
|
end
|
62
33
|
it 'list' do
|
63
|
-
expect { @cli.
|
64
|
-
expect {
|
34
|
+
expect { @cli.del }.to output(/#{match_delete_list}/).to_stdout
|
35
|
+
expect { @cli.show }.to_not output(/hoge/).to_stdout
|
65
36
|
end
|
66
37
|
end
|
67
38
|
end
|
68
39
|
end
|
69
40
|
describe 'zsh' do
|
70
|
-
|
41
|
+
ENV['SHELL'] = '/bin/zsh'
|
42
|
+
add_history
|
43
|
+
hist_file = File.expand_path('~/.zsh_history')
|
44
|
+
file_write(hist_file,'abcd ABCD 1234 あいうえ', 'a')
|
71
45
|
it_should_behave_like 'shell test'
|
72
46
|
end
|
73
47
|
|
74
48
|
describe 'bash' do
|
75
|
-
|
49
|
+
ENV['SHELL'] = '/bin/bash'
|
50
|
+
add_history
|
76
51
|
it_should_behave_like 'shell test'
|
77
52
|
end
|
78
53
|
end
|
data/spec/lib/tail_spec.rb
CHANGED
@@ -7,15 +7,11 @@ describe AM::Tail do
|
|
7
7
|
add_history
|
8
8
|
end
|
9
9
|
|
10
|
-
it '
|
11
|
-
expect(@tail.
|
12
|
-
expect(@tail.get_last_five_command[0]).to match(/[a-z]+/)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'get_last_command' do
|
16
|
-
expect(@tail.get_last_command.length).to be >= 1
|
10
|
+
it 'get_last_commands' do
|
11
|
+
expect(@tail.get_last_command.length).to eq AM::TAIL_LINE
|
17
12
|
expect(@tail.get_last_command[0]).to match(/[a-z]+/)
|
18
13
|
end
|
14
|
+
|
19
15
|
end
|
20
16
|
|
21
17
|
describe 'zsh' do
|
data/spec/spec_helper.rb
CHANGED
@@ -24,10 +24,8 @@ rails
|
|
24
24
|
cd /hoge/fuga/hoge/fuga
|
25
25
|
: 1426500307:0;cat /hoge | grep 'hoge'
|
26
26
|
cat /hoge | grep 'hoge'
|
27
|
-
: 1426500358:0;pepabo
|
28
|
-
pepabo
|
29
27
|
: 1426500618:0;abcd ABCD 1234 あいうえ
|
30
|
-
abcd ABCD 1234 あいうえ
|
28
|
+
abcd ABCD 1234 あいうえ
|
31
29
|
EOS
|
32
30
|
hist_file = File.expand_path(AM::Tail.new(AM::Config.new).profile[:file])
|
33
31
|
type = File.exists?(hist_file)? 'a' : 'w'
|
@@ -50,34 +48,45 @@ end
|
|
50
48
|
def match_current_config
|
51
49
|
return <<'EOS'
|
52
50
|
|
53
|
-
|
51
|
+
------------------------------------------------------------
|
52
|
+
current registered alias
|
54
53
|
1 : hoge = 'fuga'
|
55
54
|
2 : 123 = '123'
|
56
55
|
3 : ABC = 'ABC'
|
57
56
|
4 : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
|
58
57
|
5 : ほげ = 'ふがふが'
|
58
|
+
------------------------------------------------------------
|
59
59
|
|
60
60
|
EOS
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
63
|
+
def match_last_command
|
64
64
|
return <<'EOS'
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
1 : rake
|
66
|
+
2 : rake
|
67
|
+
3 : rails
|
68
|
+
4 : rails
|
69
|
+
5 : cd /hoge/fuga/hoge/fuga
|
70
|
+
6 : cd /hoge/fuga/hoge/fuga
|
71
|
+
7 : cat /hoge | grep 'hoge'
|
72
|
+
8 : cat /hoge | grep 'hoge'
|
73
|
+
9 : abcd ABCD 1234 あいうえ
|
74
|
+
10 : abcd ABCD 1234 あいうえ
|
70
75
|
EOS
|
71
76
|
end
|
72
77
|
|
73
78
|
def match_delete_list
|
74
79
|
return <<'EOS'
|
75
|
-
|
80
|
+
|
81
|
+
------------------------------------------------------------
|
82
|
+
current registered alias
|
76
83
|
1 : hoge = 'fuga'
|
77
84
|
2 : 123 = '123'
|
78
85
|
3 : ABC = 'ABC'
|
79
86
|
4 : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
|
80
87
|
5 : ほげ = 'ふがふが'
|
88
|
+
------------------------------------------------------------
|
89
|
+
|
81
90
|
EOS
|
82
91
|
end
|
83
92
|
def file_load(file_name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: am
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ka-yamashita
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|