ruby-zoom 3.5.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/bin/z +189 -147
  3. data/bin/zc +189 -147
  4. data/bin/zf +189 -147
  5. data/bin/zg +189 -147
  6. data/bin/zl +189 -147
  7. data/bin/zr +189 -147
  8. data/lib/zoom.rb +48 -604
  9. data/lib/zoom/cache.rb +253 -0
  10. data/lib/zoom/cache/result.rb +49 -0
  11. data/lib/zoom/config.rb +156 -0
  12. data/lib/zoom/editor.rb +121 -0
  13. data/lib/zoom/error.rb +6 -6
  14. data/lib/zoom/error/{executable_not_found_error.rb → executable_not_found.rb} +1 -3
  15. data/lib/zoom/error/invalid_color.rb +5 -0
  16. data/lib/zoom/error/{invalid_tag_error.rb → invalid_tag.rb} +1 -3
  17. data/lib/zoom/error/{profile_class_unknown_error.rb → profile_class_unknown.rb} +1 -3
  18. data/lib/zoom/error/{profile_does_not_exist_error.rb → profile_does_not_exist.rb} +1 -3
  19. data/lib/zoom/error/profile_not_named.rb +7 -0
  20. data/lib/zoom/profile.rb +162 -66
  21. data/lib/zoom/profile/ack.rb +5 -30
  22. data/lib/zoom/profile/ag.rb +2 -37
  23. data/lib/zoom/profile/find.rb +2 -25
  24. data/lib/zoom/profile/grep.rb +2 -44
  25. data/lib/zoom/profile/passwords.rb +27 -59
  26. data/lib/zoom/profile/pt.rb +2 -26
  27. data/lib/zoom/profile_manager.rb +49 -0
  28. data/lib/zoom/wish/add_wish.rb +58 -0
  29. data/lib/zoom/wish/color_wish.rb +147 -0
  30. data/lib/zoom/wish/copy_wish.rb +57 -0
  31. data/lib/zoom/wish/delete_wish.rb +51 -0
  32. data/lib/zoom/wish/edit_wish.rb +130 -0
  33. data/lib/zoom/wish/editor_wish.rb +31 -0
  34. data/lib/zoom/wish/list_wish.rb +58 -0
  35. data/lib/zoom/wish/rename_wish.rb +69 -0
  36. data/lib/zoom/wish/reset_wish.rb +40 -0
  37. data/lib/zoom/wish/use_wish.rb +61 -0
  38. metadata +118 -24
  39. data/lib/string.rb +0 -48
  40. data/lib/zoom/error/profile_already_exists_error.rb +0 -8
  41. data/lib/zoom/error/profile_can_not_be_modified_error.rb +0 -8
@@ -0,0 +1,57 @@
1
+ require "djinni"
2
+
3
+ class CopyWish < Djinni::Wish
4
+ def aliases
5
+ return ["copy", "cp"]
6
+ end
7
+
8
+ def description
9
+ return "Copy the specified profile"
10
+ end
11
+
12
+ def execute(args, djinni_env = {})
13
+ if (args.split(" ").length != 2)
14
+ usage
15
+ return
16
+ end
17
+
18
+ config = djinni_env["config"]
19
+
20
+ name, new = args.split(" ")
21
+ if (!config.has_profile?(name))
22
+ puts "Profile does not exist: #{name}"
23
+ elsif (config.has_profile?(new))
24
+ puts "Profile already exists: #{new}"
25
+ else
26
+ profiles = config.get_profiles
27
+ profiles[new] = profiles[name].clone
28
+ profiles[new].name(new)
29
+ config.set_profiles(profiles)
30
+ end
31
+ end
32
+
33
+ def tab_complete(input, djinni_env = {})
34
+ return [{}, "", ""] if (input.include?(" "))
35
+
36
+ profiles = djinni_env["config"].get_profiles
37
+ completions = Hash.new
38
+
39
+ profiles.keys.sort do |a, b|
40
+ a.downcase <=> b.downcase
41
+ end.each do |name|
42
+ profile = profiles[name]
43
+ completions[name] = profile.to_s.split("\n")[1].strip
44
+ end
45
+
46
+ completions.keep_if do |name, desc|
47
+ name.downcase.start_with?(input.downcase)
48
+ end
49
+
50
+ return [completions, input, " "]
51
+ end
52
+
53
+ def usage
54
+ puts "#{aliases.join(", ")} <name> <new_name>"
55
+ puts " #{description}."
56
+ end
57
+ end
@@ -0,0 +1,51 @@
1
+ require "djinni"
2
+
3
+ class DeleteWish < Djinni::Wish
4
+ def aliases
5
+ return ["delete", "rm"]
6
+ end
7
+
8
+ def description
9
+ return "Delete the specifed profile"
10
+ end
11
+
12
+ def execute(args, djinni_env = {})
13
+ config = djinni_env["config"]
14
+ profiles = config.get_profiles
15
+ args.split(" ").each do |arg|
16
+ if (!config.has_profile?(arg))
17
+ puts "Profile does not exist: #{arg}"
18
+ elsif (config.current_profile_name == arg)
19
+ puts "Can't delete current profile: #{arg}"
20
+ else
21
+ profiles.delete(arg)
22
+ end
23
+ end
24
+ config.set_profiles(profiles)
25
+ end
26
+
27
+ def tab_complete(input, djinni_env = {})
28
+ profiles = djinni_env["config"].get_profiles
29
+ completions = Hash.new
30
+
31
+ profiles.keys.sort do |a, b|
32
+ a.downcase <=> b.downcase
33
+ end.each do |name|
34
+ profile = profiles[name]
35
+ completions[name] = profile.to_s.split("\n")[1].strip
36
+ end
37
+
38
+ last = input.rpartition(" ")[-1]
39
+
40
+ completions.keep_if do |name, desc|
41
+ name.downcase.start_with?(last.downcase)
42
+ end
43
+
44
+ return [completions, last, " "]
45
+ end
46
+
47
+ def usage
48
+ puts "#{aliases.join(", ")} <name>...[name]"
49
+ puts " #{description}."
50
+ end
51
+ end
@@ -0,0 +1,130 @@
1
+ require "djinni"
2
+
3
+ class EditWish < Djinni::Wish
4
+ def aliases
5
+ return ["config", "edit", "set"]
6
+ end
7
+
8
+ def description
9
+ return "Configure profile"
10
+ end
11
+
12
+ def execute(args, djinni_env = {})
13
+ n, args = args.split(" ", 2)
14
+
15
+ if (args.nil?)
16
+ usage
17
+ return
18
+ end
19
+
20
+ config = djinni_env["config"]
21
+ if (!config.has_profile?(n))
22
+ puts "Profile does not exist: #{n}"
23
+ return
24
+ end
25
+
26
+ f, found, v = args.partition(" ")
27
+
28
+ case f
29
+ when "class", "operator"
30
+ if (found.empty?)
31
+ usage
32
+ return
33
+ end
34
+ end
35
+
36
+ profiles = config.get_profiles
37
+ profile = profiles[n]
38
+
39
+ case f
40
+ when "after"
41
+ profile.after(v)
42
+ when "before"
43
+ profile.before(v)
44
+ when "class"
45
+ if (!@classes.has_key?(v))
46
+ puts "Class does not exist: #{v}"
47
+ return
48
+ end
49
+
50
+ profile = Zoom::Profile.profile_by_name(v).new(n)
51
+ profiles[n] = profile
52
+ when "flags"
53
+ profile.flags(v)
54
+ when "operator"
55
+ profile.operator(v)
56
+ else
57
+ usage
58
+ return
59
+ end
60
+
61
+ config.set_profiles(profiles)
62
+ end
63
+
64
+ def initialize
65
+ @classes = Hash.new
66
+ [Zoom::Profile].concat(Zoom::Profile.subclasses).each do |c|
67
+ @classes[c.to_s] = c.new(c.to_s).to_s.split("\n")[1].strip
68
+ end
69
+ @fields = {
70
+ "after" => "Append any follow up commands",
71
+ "before" => "Prepend any ENV vars",
72
+ "class" => "Modify the class",
73
+ "flags" => "Specify any additional flags",
74
+ "operator" => "Specify an alternative operator"
75
+ }
76
+ end
77
+
78
+ def tab_complete(input, djinni_env = {})
79
+ n, input = input.split(" ", 2)
80
+ n ||= ""
81
+
82
+ if (input.nil?)
83
+ profiles = djinni_env["config"].get_profiles
84
+ completions = Hash.new
85
+
86
+ profiles.keys.sort do |a, b|
87
+ a.downcase <=> b.downcase
88
+ end.each do |name|
89
+ profile = profiles[name]
90
+ completions[name] = profile.to_s.split("\n")[1].strip
91
+ end
92
+
93
+ completions.keep_if do |name, desc|
94
+ name.downcase.start_with?(n.downcase)
95
+ end
96
+
97
+ return [completions, n, " "]
98
+ end
99
+
100
+ f, found, v = input.rpartition(" ")
101
+
102
+ if (found.empty?)
103
+ f = v
104
+ completions = @fields.select do |field, desc|
105
+ field.downcase.start_with?(f.downcase)
106
+ end
107
+ return [completions, f, " "]
108
+ end
109
+
110
+ case f
111
+ when "class"
112
+ completions = @classes.select do |clas, desc|
113
+ clas.downcase.start_with?(v.downcase)
114
+ end
115
+ return [completions, v, ""]
116
+ else
117
+ return [{}, "", ""]
118
+ end
119
+ end
120
+
121
+ def usage
122
+ puts "#{aliases.join(", ")} <name> <field> <value>"
123
+ puts " #{description}."
124
+ puts
125
+ puts "FIELDS"
126
+ @fields.each do |field, desc|
127
+ puts " #{field}"
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,31 @@
1
+ require "djinni"
2
+ require "scoobydoo"
3
+
4
+ class EditorWish < Djinni::Wish
5
+ def aliases
6
+ return ["editor"]
7
+ end
8
+
9
+ def description
10
+ return "Configure editor"
11
+ end
12
+
13
+ def execute(args, djinni_env = {})
14
+ if (args.include?(" "))
15
+ usage
16
+ return
17
+ end
18
+
19
+ config = djinni_env["config"]
20
+ if (ScoobyDoo.where_are_you(args))
21
+ config.editor(args)
22
+ else
23
+ puts "Editor not found: #{args}"
24
+ end
25
+ end
26
+
27
+ def usage
28
+ puts "#{aliases.join(", ")} <value>"
29
+ puts " #{description}."
30
+ end
31
+ end
@@ -0,0 +1,58 @@
1
+ require "djinni"
2
+
3
+ class ListWish < Djinni::Wish
4
+ def aliases
5
+ return ["la", "list", "ls"]
6
+ end
7
+
8
+ def description
9
+ return "List details for current/all profiles"
10
+ end
11
+
12
+ def execute(args, djinni_env = {})
13
+ if (!args.empty? && (args != "all"))
14
+ usage
15
+ return
16
+ end
17
+
18
+ config = djinni_env["config"]
19
+ input = djinni_env["djinni_input"]
20
+ input = "la" if (!args.empty?)
21
+
22
+ case input
23
+ when "la"
24
+ profiles = config.get_profiles
25
+ profiles.keys.sort do |a, b|
26
+ a.downcase <=> b.downcase
27
+ end.each do |name|
28
+ print_profile(profiles[name])
29
+ end
30
+ else
31
+ profile = config.get_profiles[config.current_profile_name]
32
+ print_profile(profile)
33
+ end
34
+ end
35
+
36
+ def print_profile(profile)
37
+ first = true
38
+ profile.to_s.scan(/\S.{0,76}\S(?=\s|$)|\S+/).each do |line|
39
+ if (first)
40
+ puts line
41
+ first = false
42
+ else
43
+ puts " #{line}"
44
+ end
45
+ end
46
+ end
47
+ private :print_profile
48
+
49
+ def tab_complete(input, djinni_env = {})
50
+ return [{}, "", ""] if (input.include?(" "))
51
+ return [{"all" => "List all profiles"}, input, ""]
52
+ end
53
+
54
+ def usage
55
+ puts "#{aliases.join(", ")} [all]"
56
+ puts " #{description}."
57
+ end
58
+ end
@@ -0,0 +1,69 @@
1
+ require "djinni"
2
+
3
+ class RenameWish < Djinni::Wish
4
+ def aliases
5
+ return ["mv", "rename"]
6
+ end
7
+
8
+ def description
9
+ return "Rename the specified profile"
10
+ end
11
+
12
+ def execute(args, djinni_env = {})
13
+ if (args.split(" ").length != 2)
14
+ usage
15
+ return
16
+ end
17
+
18
+ config = djinni_env["config"]
19
+
20
+ old, new = args.split(" ")
21
+ if (!config.has_profile?(old))
22
+ puts "Profile does not exist: #{old}"
23
+ elsif (config.has_profile?(new))
24
+ puts "Profile already exists: #{new}"
25
+ else
26
+ profiles = config.get_profiles
27
+ profiles[new] = profiles.delete(old)
28
+ profiles[new].name(new)
29
+ config.set_profiles(profiles)
30
+
31
+ # Update prompt
32
+ if (config.current_profile_name == old)
33
+ config.current_profile_name(new)
34
+ prompt_color = djinni_env["prompt_color"]
35
+ if (prompt_color)
36
+ prompt = "zoom(#{new})> ".send(prompt_color)
37
+ else
38
+ prompt = "zoom(#{new})> "
39
+ end
40
+ djinni_env["djinni_prompt"] = prompt
41
+ end
42
+ end
43
+ end
44
+
45
+ def tab_complete(input, djinni_env = {})
46
+ return [{}, "", ""] if (input.include?(" "))
47
+
48
+ profiles = djinni_env["config"].get_profiles
49
+ completions = Hash.new
50
+
51
+ profiles.keys.sort do |a, b|
52
+ a.downcase <=> b.downcase
53
+ end.each do |name|
54
+ profile = profiles[name]
55
+ completions[name] = profile.to_s.split("\n")[1].strip
56
+ end
57
+
58
+ completions.keep_if do |name, desc|
59
+ name.downcase.start_with?(input.downcase)
60
+ end
61
+
62
+ return [completions, input, " "]
63
+ end
64
+
65
+ def usage
66
+ puts "#{aliases.join(", ")} <old_name> <new_name>"
67
+ puts " #{description}."
68
+ end
69
+ end
@@ -0,0 +1,40 @@
1
+ require "djinni"
2
+
3
+ class ResetWish < Djinni::Wish
4
+ def aliases
5
+ return ["default", "reset"]
6
+ end
7
+
8
+ def description
9
+ return "Create default profiles"
10
+ end
11
+
12
+ def execute(args, djinni_env = {})
13
+ if (!args.empty?)
14
+ usage
15
+ return
16
+ end
17
+
18
+ FileUtils.rm_f(Pathname.new("~/.zoomrc").expand_path)
19
+ config = djinni_env["config"]
20
+ config.default_config
21
+
22
+ cache = djinni_env["cache"]
23
+ cache.clear
24
+
25
+ # Update prompt
26
+ default = config.current_profile_name
27
+ prompt_color = djinni_env["prompt_color"]
28
+ if (prompt_color)
29
+ prompt = "zoom(#{default})> ".send(prompt_color)
30
+ else
31
+ prompt = "zoom(#{default})> "
32
+ end
33
+ djinni_env["djinni_prompt"] = prompt
34
+ end
35
+
36
+ def usage
37
+ puts "#{aliases.join(", ")}"
38
+ puts " #{description}."
39
+ end
40
+ end
@@ -0,0 +1,61 @@
1
+ require "djinni"
2
+
3
+ class UseWish < Djinni::Wish
4
+ def aliases
5
+ return ["use"]
6
+ end
7
+
8
+ def description
9
+ return "Set the specifed profile as the current profile name"
10
+ end
11
+
12
+ def execute(args, djinni_env = {})
13
+ if (args.include?(" "))
14
+ usage
15
+ return
16
+ end
17
+
18
+ config = djinni_env["config"]
19
+
20
+ if (!config.has_profile?(args))
21
+ puts "Profile does not exist: #{args}"
22
+ return
23
+ end
24
+
25
+ config.current_profile_name(args)
26
+
27
+ # Update prompt
28
+ prompt_color = djinni_env["prompt_color"]
29
+ if (prompt_color)
30
+ prompt = "zoom(#{args})> ".send(prompt_color)
31
+ else
32
+ prompt = "zoom(#{args})> "
33
+ end
34
+ djinni_env["djinni_prompt"] = prompt
35
+ end
36
+
37
+ def tab_complete(input, djinni_env = {})
38
+ return [{}, "", ""] if (input.include?(" "))
39
+
40
+ profiles = djinni_env["config"].get_profiles
41
+ completions = Hash.new
42
+
43
+ profiles.keys.sort do |a, b|
44
+ a.downcase <=> b.downcase
45
+ end.each do |name|
46
+ profile = profiles[name]
47
+ completions[name] = profile.to_s.split("\n")[1].strip
48
+ end
49
+
50
+ completions.keep_if do |name, desc|
51
+ name.downcase.start_with?(input.downcase)
52
+ end
53
+
54
+ return [completions, input, " "]
55
+ end
56
+
57
+ def usage
58
+ puts "#{aliases.join(", ")} <name>"
59
+ puts " #{description}."
60
+ end
61
+ end