aka2 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/changelog.md +5 -5
- data/lib/aka.rb +155 -35
- data/lib/aka/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40626cc2cfc54d3962ec5658ecf5f38c4b305571
|
4
|
+
data.tar.gz: 1f50860a5d9a7083791f7b954837bfec1c091959
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6aee9b32cb2e7b611e40ada21e45c9d2ba1e73f3557b46bc98888a5280478d58f077948224a81c83c91165a6e3d7f052715b0a47700c3655c351aaa18c6a0a08
|
7
|
+
data.tar.gz: e6fd42de9861d0f8b33db36a7ca8335fe32927e03444a7daea2624c1052c39bf6f515d1d943570eb1e643458bb85c976ee0cb1e1362cad162bfb2caab6fd0730
|
data/changelog.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
## v0.1.
|
2
|
-
|
3
|
-
*
|
4
|
-
|
5
|
-
## v0.1.7
|
1
|
+
## v0.1.9
|
2
|
+
* Added -g option to add grouping to alias
|
3
|
+
* Added -g option to find grouping based on group name
|
4
|
+
* Usual clean up
|
6
5
|
|
6
|
+
## v0.1.7 + v0.1.8
|
7
7
|
* Add numbering option for list
|
8
8
|
* Add validation for list method
|
9
9
|
* Beautify aka output
|
data/lib/aka.rb
CHANGED
@@ -27,7 +27,7 @@ module Aka
|
|
27
27
|
# aka where
|
28
28
|
desc "where", "locate your dotfile"
|
29
29
|
def where
|
30
|
-
puts readYML("#{Dir.
|
30
|
+
puts readYML("#{Dir.pwd}/.aka/.config")["dotfile"]
|
31
31
|
end
|
32
32
|
|
33
33
|
#
|
@@ -39,7 +39,7 @@ module Aka
|
|
39
39
|
method_options :to => :string
|
40
40
|
method_options :login => :string
|
41
41
|
def upload
|
42
|
-
if options.from
|
42
|
+
if options.from && options.to && options.login
|
43
43
|
password = get_password()
|
44
44
|
|
45
45
|
if File.exists?(options.from)
|
@@ -79,7 +79,7 @@ module Aka
|
|
79
79
|
method_options :to => :string
|
80
80
|
method_options :login => :string
|
81
81
|
def upload
|
82
|
-
if options.from
|
82
|
+
if options.from && options.to && options.login
|
83
83
|
password = get_password()
|
84
84
|
|
85
85
|
if File.exists?(options.from)
|
@@ -110,23 +110,26 @@ module Aka
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
-
|
113
|
+
#################
|
114
114
|
# GENERATE
|
115
|
-
|
115
|
+
#################
|
116
116
|
desc "generate", "generate an alias (short alias: g)"
|
117
|
-
|
117
|
+
method_option :last, :type => :boolean, :aliases => '-l', :desc => ''
|
118
|
+
method_option :group, :type => :string, :aliases => '-g', :desc => '', :default => 'default'
|
118
119
|
def generate args
|
119
120
|
result = false
|
120
121
|
if options.last?
|
122
|
+
#we need to add group here.
|
121
123
|
result = add(add_last_command(parseARGS(args))) if args
|
122
124
|
else
|
123
|
-
|
124
|
-
|
125
|
+
#we should probably phase out add()
|
126
|
+
result = add_with_group(parseARGS(args), options.group) if args
|
127
|
+
if options.proj? && result == true
|
125
128
|
FileUtils.touch("#{Dir.pwd}/.aka")
|
126
129
|
add_to_proj(args)
|
127
130
|
end
|
128
131
|
end
|
129
|
-
reload_dot_file if result == true
|
132
|
+
reload_dot_file if result == true && !options.noreload
|
130
133
|
end
|
131
134
|
|
132
135
|
#
|
@@ -137,8 +140,8 @@ module Aka
|
|
137
140
|
def destroy(*args)
|
138
141
|
args.each_with_index do |value, index|
|
139
142
|
result = remove(value)
|
140
|
-
unalias_the(value) if !options.nounalias
|
141
|
-
reload_dot_file if result == true
|
143
|
+
unalias_the(value) if !options.nounalias && result == true
|
144
|
+
reload_dot_file if result == true && !options.noreload
|
142
145
|
end
|
143
146
|
end
|
144
147
|
|
@@ -172,9 +175,14 @@ module Aka
|
|
172
175
|
#
|
173
176
|
desc "find", "find an alias (short alias: f)"
|
174
177
|
method_options :force => :boolean
|
178
|
+
method_option :group, :type => :string, :aliases => '-g', :desc => ''
|
175
179
|
def find *args
|
176
|
-
|
177
|
-
|
180
|
+
if options.group
|
181
|
+
search_alias_with_group_name(options.group)
|
182
|
+
else
|
183
|
+
args.each_with_index do |value, index|
|
184
|
+
search_alias_return_alias_tokens(value)
|
185
|
+
end
|
178
186
|
end
|
179
187
|
end
|
180
188
|
|
@@ -444,9 +452,28 @@ module Aka
|
|
444
452
|
return [username, domain, port]
|
445
453
|
end
|
446
454
|
|
455
|
+
def add_with_group input, name_of_group
|
456
|
+
if input && search_alias_return_alias_tokens(input).first == false && not_empty_alias(input) == false
|
457
|
+
array = input.split("=")
|
458
|
+
group_name = "# => #{name_of_group}"
|
459
|
+
full_command = "alias #{array.first}='#{array[1]}' #{group_name}".gsub("\n","") #remove new line in command
|
460
|
+
print_out_command = "aka g #{array.first}='#{array[1]}'"
|
461
|
+
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
462
|
+
|
463
|
+
File.open(str, 'a') { |file| file.write("\n" +full_command) }
|
464
|
+
# puts "#{print_out_command} is added to #{readYML("#{Dir.home}/.aka/.config")["dotfile"]}"
|
465
|
+
puts "Created: ".green + "#{print_out_command} " + "in #{name_of_group} group."
|
466
|
+
|
467
|
+
return true
|
468
|
+
else
|
469
|
+
puts "The alias is already present. Use 'aka -h' to see all the useful commands."
|
470
|
+
return false
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
447
474
|
# add
|
448
475
|
def add input
|
449
|
-
if input
|
476
|
+
if input && search_alias_return_alias_tokens(input).first == false && not_empty_alias(input) == false
|
450
477
|
array = input.split("=")
|
451
478
|
full_command = "alias #{array.first}='#{array[1]}'".gsub("\n","") #remove new line in command
|
452
479
|
print_out_command = "aka g #{array.first}='#{array[1]}'"
|
@@ -471,6 +498,50 @@ module Aka
|
|
471
498
|
return array[1].strip == ""
|
472
499
|
end
|
473
500
|
|
501
|
+
#list
|
502
|
+
def search_alias_with_group_name name
|
503
|
+
if name == "group"
|
504
|
+
name = "default"
|
505
|
+
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
506
|
+
|
507
|
+
if content = File.open(str).read
|
508
|
+
content.gsub!(/\r\n?/, "\n")
|
509
|
+
content_array = content.split("\n")
|
510
|
+
content_array.each_with_index { |line, index|
|
511
|
+
value = line.split(" ")
|
512
|
+
containsCommand = line.split('=') #containsCommand[1]
|
513
|
+
if value.length > 1 && value.first == "alias"
|
514
|
+
answer = value[1].split("=") #contains the alias
|
515
|
+
group_name = line.scan(/# => ([a-zA-z]*)/).first if line.scan(/# => ([a-zA-z]*)/)
|
516
|
+
if group_name != nil && group_name.first == name
|
517
|
+
containsCommand[1].slice!(0) && containsCommand[1].slice!(containsCommand[1].length-1) if containsCommand[1] != nil && containsCommand[1][0] == "'" && containsCommand[1][containsCommand[1].length-1] == "'"
|
518
|
+
puts "aka g " + "#{answer.first}".red + "=#{containsCommand[1]}"
|
519
|
+
end
|
520
|
+
end
|
521
|
+
}
|
522
|
+
end
|
523
|
+
else
|
524
|
+
|
525
|
+
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
526
|
+
if content = File.open(str).read
|
527
|
+
content.gsub!(/\r\n?/, "\n")
|
528
|
+
content_array = content.split("\n")
|
529
|
+
content_array.each_with_index { |line, index|
|
530
|
+
value = line.split(" ")
|
531
|
+
containsCommand = line.split('=') #containsCommand[1]
|
532
|
+
if value.length > 1 && value.first == "alias"
|
533
|
+
answer = value[1].split("=") #contains the alias
|
534
|
+
group_name = line.scan(/# => ([a-zA-z]*)/).first if line.scan(/# => ([a-zA-z]*)/)
|
535
|
+
if group_name != nil && group_name.first == name
|
536
|
+
containsCommand[1].slice!(0) && containsCommand[1].slice!(containsCommand[1].length-1) if containsCommand[1] != nil && containsCommand[1][0] == "'" && containsCommand[1][containsCommand[1].length-1] == "'"
|
537
|
+
puts "aka g " + "#{answer.first}".red + "=#{containsCommand[1]}"
|
538
|
+
end
|
539
|
+
end
|
540
|
+
}
|
541
|
+
end
|
542
|
+
end
|
543
|
+
end
|
544
|
+
|
474
545
|
# show alias
|
475
546
|
def search_alias_return_alias_tokens argument
|
476
547
|
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
@@ -482,7 +553,7 @@ module Aka
|
|
482
553
|
value = line.split(" ")
|
483
554
|
# puts "value -> #{value}"
|
484
555
|
containsCommand = line.split('=') #containsCommand[1]
|
485
|
-
if value.length > 1
|
556
|
+
if value.length > 1 && value.first == "alias"
|
486
557
|
# answer = value[1].split("=")
|
487
558
|
answer = value[1].split("=") #contains the alias
|
488
559
|
|
@@ -491,7 +562,7 @@ module Aka
|
|
491
562
|
this_alias = answer.first
|
492
563
|
answer.slice!(0) #rmove the first
|
493
564
|
# puts "before ->#{containsCommand[1]}"
|
494
|
-
containsCommand[1].slice!(0)
|
565
|
+
containsCommand[1].slice!(0) && containsCommand[1].slice!(containsCommand[1].length-1) if containsCommand[1] != nil && containsCommand[1][0] == "'" && containsCommand[1][containsCommand[1].length-1] == "'"
|
495
566
|
# puts "before 2 ->#{containsCommand[1]}"
|
496
567
|
|
497
568
|
# puts "join ->#{containsCommand[1]}"
|
@@ -517,10 +588,10 @@ module Aka
|
|
517
588
|
content_array= content.split("\n")
|
518
589
|
content_array.each_with_index { |line, index|
|
519
590
|
value = line.split(" ")
|
520
|
-
if value.length > 1
|
591
|
+
if value.length > 1 && value.first == "alias"
|
521
592
|
answer = value[1].split("=")
|
522
593
|
if answer.first == input
|
523
|
-
content_array.delete_at(index)
|
594
|
+
content_array.delete_at(index) && write_with_newline(content_array)
|
524
595
|
print_out_command = "aka g #{input}=#{line.split("=")[1]}"
|
525
596
|
# puts "removed: #{print_out_command} is removed from #{str}".red
|
526
597
|
|
@@ -548,7 +619,7 @@ module Aka
|
|
548
619
|
content_array= content.split("\n")
|
549
620
|
content_array.each_with_index { |line, index|
|
550
621
|
if line == "source \"/home/ryan/.aka/autosource\""
|
551
|
-
content_array.delete_at(index)
|
622
|
+
content_array.delete_at(index) && write_with_newline(content_array)
|
552
623
|
# puts "---> removed: source \"/home/ryan/.aka/autosource\""
|
553
624
|
puts "Removed: ".red + "source \"/home/ryan/.aka/autosource\""
|
554
625
|
|
@@ -625,7 +696,7 @@ module Aka
|
|
625
696
|
content_array= content.split("\n")
|
626
697
|
content_array.each_with_index { |line, index|
|
627
698
|
value = line.split(" ")
|
628
|
-
if value.length > 1
|
699
|
+
if value.length > 1 && value.first == "function"
|
629
700
|
answer = value[1].split("=")
|
630
701
|
function_count += 1
|
631
702
|
end
|
@@ -643,7 +714,7 @@ module Aka
|
|
643
714
|
content_array= content.split("\n")
|
644
715
|
content_array.each_with_index { |line, index|
|
645
716
|
value = line.split(" ")
|
646
|
-
if value.length > 1
|
717
|
+
if value.length > 1 && value.first == "export"
|
647
718
|
answer = value[1].split("=")
|
648
719
|
export_count += 1
|
649
720
|
end
|
@@ -664,7 +735,7 @@ module Aka
|
|
664
735
|
content_array= content.split("\n")
|
665
736
|
content_array.each_with_index { |line, index|
|
666
737
|
value = line.split(" ")
|
667
|
-
if value.length > 1
|
738
|
+
if value.length > 1 && value.first == "alias"
|
668
739
|
answer = value[1].split("=")
|
669
740
|
alias_count += 1
|
670
741
|
end
|
@@ -793,7 +864,7 @@ module Aka
|
|
793
864
|
# read location
|
794
865
|
def read location
|
795
866
|
answer = dot_location_exists?(location)
|
796
|
-
if answer == true
|
867
|
+
if answer == true && content = File.open(location).read
|
797
868
|
return content
|
798
869
|
end
|
799
870
|
return ""
|
@@ -836,7 +907,41 @@ module Aka
|
|
836
907
|
total_aliases = []
|
837
908
|
content_array.each_with_index { |line, index|
|
838
909
|
value = line.split(" ")
|
839
|
-
if value.length > 1
|
910
|
+
if value.length > 1 && value.first == "alias"
|
911
|
+
total_aliases.push(line)
|
912
|
+
end
|
913
|
+
}
|
914
|
+
puts ""
|
915
|
+
if total_aliases.count > howmany
|
916
|
+
total_aliases.last(howmany).each_with_index do |line, index|
|
917
|
+
splitted= line.split('=')
|
918
|
+
puts "#{total_aliases.count - howmany + index+1}. aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
919
|
+
# puts "#{total_aliases.count - howmany + index+1}. aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
920
|
+
# puts "#{total_aliases.count - howmany + index+1}. " + splitted[0] + "=" + splitted[1].red
|
921
|
+
end
|
922
|
+
else
|
923
|
+
total_aliases.last(howmany).each_with_index do |line, index|
|
924
|
+
splitted= line.split('=')
|
925
|
+
# puts "#{index+1}. " + splitted[0] + "=" + splitted[1].red
|
926
|
+
puts "#{index+1}. aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
927
|
+
# puts "#{index+1}. aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
928
|
+
end
|
929
|
+
end
|
930
|
+
puts ""
|
931
|
+
end
|
932
|
+
end
|
933
|
+
|
934
|
+
def show_last_with_group(list_number=false, howmany=10, group)
|
935
|
+
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
936
|
+
|
937
|
+
if content = File.open(str).read
|
938
|
+
content.gsub!(/\r\n?/, "\n")
|
939
|
+
content_array = content.split("\n")
|
940
|
+
|
941
|
+
total_aliases = []
|
942
|
+
content_array.each_with_index { |line, index|
|
943
|
+
value = line.split(" ")
|
944
|
+
if value.length > 1 && value.first == "alias"
|
840
945
|
total_aliases.push(line)
|
841
946
|
end
|
842
947
|
}
|
@@ -844,14 +949,26 @@ module Aka
|
|
844
949
|
if total_aliases.count > howmany
|
845
950
|
total_aliases.last(howmany).each_with_index do |line, index|
|
846
951
|
splitted= line.split('=')
|
847
|
-
|
952
|
+
if list_number
|
953
|
+
puts "#{total_aliases.count - howmany + index+1}. aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
954
|
+
# puts "#{total_aliases.count - howmany + index+1}. aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
955
|
+
else
|
956
|
+
puts "aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
957
|
+
# puts "aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
958
|
+
end
|
848
959
|
# puts "#{total_aliases.count - howmany + index+1}. " + splitted[0] + "=" + splitted[1].red
|
849
960
|
end
|
850
961
|
else
|
851
962
|
total_aliases.last(howmany).each_with_index do |line, index|
|
852
963
|
splitted= line.split('=')
|
853
964
|
# puts "#{index+1}. " + splitted[0] + "=" + splitted[1].red
|
854
|
-
|
965
|
+
if list_number
|
966
|
+
puts "#{index+1}. aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
967
|
+
# puts "#{index+1}. aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
968
|
+
else
|
969
|
+
puts "aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
970
|
+
# puts "aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
971
|
+
end
|
855
972
|
end
|
856
973
|
end
|
857
974
|
puts ""
|
@@ -869,7 +986,7 @@ module Aka
|
|
869
986
|
total_aliases = []
|
870
987
|
content_array.each_with_index { |line, index|
|
871
988
|
value = line.split(" ")
|
872
|
-
if value.length > 1
|
989
|
+
if value.length > 1 && value.first == "alias"
|
873
990
|
total_aliases.push(line)
|
874
991
|
end
|
875
992
|
}
|
@@ -878,9 +995,11 @@ module Aka
|
|
878
995
|
total_aliases.last(howmany).each_with_index do |line, index|
|
879
996
|
splitted= line.split('=')
|
880
997
|
if list_number
|
881
|
-
puts "#{total_aliases.count - howmany + index+1}. aka g " + splitted[0].split(" ")[1] + "=" + splitted[1]
|
998
|
+
puts "#{total_aliases.count - howmany + index+1}. aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
999
|
+
# puts "#{total_aliases.count - howmany + index+1}. aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
882
1000
|
else
|
883
|
-
puts "aka g " + splitted[0].split(" ")[1] + "=" + splitted[1]
|
1001
|
+
puts "aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
1002
|
+
# puts "aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
884
1003
|
end
|
885
1004
|
# puts "#{total_aliases.count - howmany + index+1}. " + splitted[0] + "=" + splitted[1].red
|
886
1005
|
end
|
@@ -889,9 +1008,11 @@ module Aka
|
|
889
1008
|
splitted= line.split('=')
|
890
1009
|
# puts "#{index+1}. " + splitted[0] + "=" + splitted[1].red
|
891
1010
|
if list_number
|
892
|
-
puts "#{index+1}. aka g " + splitted[0].split(" ")[1] + "=" + splitted[1]
|
1011
|
+
puts "#{index+1}. aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
1012
|
+
# puts "#{index+1}. aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
893
1013
|
else
|
894
|
-
puts "aka g " + splitted[0].split(" ")[1] + "=" + splitted[1]
|
1014
|
+
puts "aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
1015
|
+
# puts "aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
895
1016
|
end
|
896
1017
|
end
|
897
1018
|
end
|
@@ -978,7 +1099,7 @@ module Aka
|
|
978
1099
|
countarray.each_with_index { |count, index|
|
979
1100
|
countarray[0..countarray.size-index].each_with_index { |x, thisindex| #always one less than total
|
980
1101
|
|
981
|
-
if index < countarray.size-1
|
1102
|
+
if index < countarray.size-1 && thisindex < countarray.size-1
|
982
1103
|
if countarray[thisindex] < countarray[thisindex+1] #if this count is less than next count
|
983
1104
|
temp = countarray[thisindex]
|
984
1105
|
countarray[thisindex] = countarray[thisindex+1]
|
@@ -1012,7 +1133,7 @@ module Aka
|
|
1012
1133
|
while check == false
|
1013
1134
|
check = true
|
1014
1135
|
content_array.each_with_index { |line, index|
|
1015
|
-
if line == ""
|
1136
|
+
if line == "" || line == "\n"
|
1016
1137
|
content_array.delete_at(index)
|
1017
1138
|
check = false
|
1018
1139
|
end
|
@@ -1039,7 +1160,7 @@ module Aka
|
|
1039
1160
|
def showBar percent
|
1040
1161
|
result = ""
|
1041
1162
|
val = percent/100 * 50
|
1042
|
-
val = 2 if val > 1
|
1163
|
+
val = 2 if val > 1 && val < 2
|
1043
1164
|
val = 1 if val.round <= 1 #for visibiity, show two bars if it's just one
|
1044
1165
|
val.round.times do
|
1045
1166
|
result += "+"
|
@@ -1178,7 +1299,6 @@ module Aka
|
|
1178
1299
|
end
|
1179
1300
|
end
|
1180
1301
|
|
1181
|
-
|
1182
1302
|
end
|
1183
1303
|
|
1184
1304
|
|
data/lib/aka/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aka2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Lim
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-10-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-scp
|
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
164
|
version: '0'
|
165
165
|
requirements: []
|
166
166
|
rubyforge_project:
|
167
|
-
rubygems_version: 2.4.
|
167
|
+
rubygems_version: 2.4.8
|
168
168
|
signing_key:
|
169
169
|
specification_version: 4
|
170
170
|
summary: The Missing Alias Manager
|