dynmenu 0.1.4 → 0.1.6

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: 7fbef625ba9c1b1d7b7cafc3e9a6a0ff91145e22
4
- data.tar.gz: 9d03d775d72a47cba114aea4862c12fdd172c801
3
+ metadata.gz: 0b0807e826ed4e2b62a3f02414b871c7bd85692c
4
+ data.tar.gz: 8223c9004a9e0da386be65ab1e981383f23e7153
5
5
  SHA512:
6
- metadata.gz: ec1166c12fd6c14e2f35021961b93d3ec654911a27b77eb5afab0ce710c999a923e78724170eb301fe64ae2e605018ff88e3ff306853ebddac97ac7818c9f213
7
- data.tar.gz: 2643c5214aa05c60ea5688ab4e51e428a8ab8fff7e096d04d746792f0033be723c3dbf30e966970acb25249e7364d1add2334a866bc4556f181bfe9a7e47a2bc
6
+ metadata.gz: 0f76c72085fba64d0a6c70abdaac03da321ceba564effe171551df5aac7ac78cfed42104eeab2cedc413fef0fccd8e5e037769b9811bd815ce45e66a40f65607
7
+ data.tar.gz: aba4d0d4449ca58b6c1d36368aaaa9cffa3ebdb0ddcce0d3a22cf122cdde342e1348196f5abe8228739db664664f3a987abe22d4e87059e23ab0377b729ad5b4
@@ -10,7 +10,6 @@ $launcher = false
10
10
  begin
11
11
  require 'subtle/subtlext'
12
12
  $subtle = false unless Subtlext::Subtle.running?
13
- $current_client = Subtlext::Client.current
14
13
  rescue LoadError
15
14
  $subtle = false
16
15
  end
@@ -3,167 +3,185 @@ require 'uri'
3
3
 
4
4
 
5
5
  class Command
6
- @@RE_COMMAND = Regexp.new(/^[+\^\*]*.+(\s[+\^\*])*(\s[@#][A-Za-z0-9_-]+)*$/)
7
- @@RE_MODES = Regexp.new(/^[+\^\*=]+$/)
8
- @@RE_CURRENT = Regexp.new(/^&(*[+-](([A-Za-z0-9_]+-*)+))/)
9
- @@RE_METHOD = Regexp.new(/^:\s*(.*)/)
10
- @@RE_BROWSER = Regexp.new(/(chrom[e|ium]|iron|navigator|firefox|opera)/i)
11
- @@RE_SEARCH = Regexp.new(/^[gs]\s+(.*)/)
12
- @@RE_URI = Regexp.new(/^((w\s+((https?|ftp):\/\/)?)|(https?|ftp):\/\/)(?:[A-Z0-9-]+.)+[A-Z]{2,6}([\/?].+)?$/i)
13
- @@RE_PROTO = Regexp.new(/^(http|https):\/\/.*/)
14
-
15
- include Item
16
-
17
- attr_reader :tags, :views, :app, :modes, :command
18
-
19
- def initialize name, command = nil
20
- @name = name
21
- clear_subtle_vars
22
- self.command = command
6
+ RE_COMMAND = Regexp.new(/^[+\^\*]*.+(\s[+\^\*])*(\s[@#][A-Za-z0-9_-]+)*$/)
7
+ RE_MODES = Regexp.new(/^[+\^\*=]+$/)
8
+ RE_METHOD = Regexp.new(/^:\s*(.*)/)
9
+ RE_BROWSER = Regexp.new(/(chrom[e|ium]|iron|navigator|firefox|opera)/i)
10
+ RE_SEARCH = Regexp.new(/^[gs]\s+(.*)/)
11
+ RE_URI = Regexp.new(/^((w\s+((https?|ftp):\/\/)?)|(https?|ftp):\/\/)(?:[A-Z0-9-]+.)+[A-Z]{2,6}([\/?].+)?$/i)
12
+ RE_PROTO = Regexp.new(/^(http|https):\/\/.*/)
13
+ MODES = { '+' => :full, '^' => :float, '*' => :stick, '=' => :zaphod }
14
+
15
+ include Item
16
+
17
+ attr_reader :tags, :views, :app, :modes, :command
18
+
19
+ def initialize name, command = nil
20
+ @name = name
21
+ clear_subtle_vars
22
+ self.command = command
23
+ end
24
+
25
+ def clear_subtle_vars
26
+ @tags = []
27
+ @views = []
28
+ @app = ""
29
+ @modes = []
30
+ end
31
+
32
+ def encode_with coder
33
+ coder['name'] = @name
34
+ coder['command'] = @command
35
+ coder['tags'] = @tags
36
+ coder['views'] = @views
37
+ coder['app'] = @app
38
+ coder['modes'] = @modes
39
+ end
40
+
41
+ def init_with coder
42
+ @name = coder['name']
43
+ @command = coder['command']
44
+ @tags = coder['tags']
45
+ @views = coder['views']
46
+ @app = coder['app']
47
+ @modes = coder['modes']
48
+ end
49
+
50
+ def command= command
51
+ unless command.nil? || command.empty?
52
+ if RE_URI.match command
53
+ command = uri_command(Regexp.last_match(0))
54
+ elsif RE_SEARCH.match command
55
+ command = web_search Regexp.last_match(1)
56
+ elsif $subtle
57
+ command = subtle_command(command)
58
+ end
23
59
  end
60
+ @command = command
61
+ end
62
+
63
+ def uri_command uri
64
+ command = uri.split(/\s+/)[-1]
65
+ command.prepend("http://") unless RE_PROTO.match command
66
+ command = URI.parse command
67
+ end
24
68
 
25
- def clear_subtle_vars
26
- @tags = []
27
- @views = []
28
- @app = ""
29
- @modes = []
69
+ def web_search search_string, engine = :google
70
+ escaped_string = URI.escape search_string
71
+ case engine
72
+ when :duckduckgo then escaped_string.prepend "https://duckduckgo.com/?q="
73
+ else escaped_string.prepend "https://www.google.com/#q="
30
74
  end
75
+ URI.parse escaped_string
76
+ end
31
77
 
32
- def encode_with coder
33
- coder['name'] = @name
34
- coder['command'] = @command
35
- coder['tags'] = @tags
36
- coder['views'] = @views
37
- coder['app'] = @app
38
- coder['modes'] = @modes
78
+ def subtle_command command
79
+ if RE_METHOD.match(command)
80
+ command = Regexp.last_match(0).to_sym
81
+ elsif RE_COMMAND.match command
82
+ clear_subtle_vars
83
+ parse_subtle_args command.split
84
+ else
85
+ @app = command
39
86
  end
87
+ end
40
88
 
41
- def init_with coder
42
- @name = coder['name']
43
- @command = coder['command']
44
- @tags = coder['tags']
45
- @views = coder['views']
46
- @app = coder['app']
47
- @modes = coder['modes']
89
+ def parse_subtle_args args
90
+ args.each do |arg|
91
+ case arg[0]
92
+ when '#' then add_tag arg
93
+ when '@' then add_view arg
94
+ when '+', '^', '*', '=' then add_mode arg
95
+ else
96
+ set_app arg
97
+ end
98
+ end
99
+ if @views.any? and not @app.empty? and @tags.empty?
100
+ @tags << "tag_#{rand(1337)}"
48
101
  end
102
+ end
49
103
 
50
- def command= command
51
- unless command.nil? || command.empty?
52
- if @@RE_URI.match command
53
- split = Regexp.last_match(0).split(/\s+/)
54
- command = split[split.length - 1]
55
- command.prepend("http://") unless @@RE_PROTO.match command
56
- command = URI.parse command
57
- elsif @@RE_SEARCH.match command
58
- command = web_search Regexp.last_match(1)
59
- elsif $subtle
60
- if @@RE_METHOD.match(command)
61
- command = Regexp.last_match(0).to_sym
62
- elsif @@RE_COMMAND.match command
63
- clear_subtle_vars
64
-
65
- command.split.each do |arg|
66
- case arg[0]
67
- when '#' then @tags << arg[1..-1]
68
- when '@' then @views << arg[1..-1]
69
- when '+', '^', '*','='
70
- mode_s = @@RE_MODES.match(arg).to_s
71
- @modes += mode_s.split(//).map! do |c|
72
- case c
73
- when '+' then :full
74
- when '^' then :float
75
- when '*' then :stick
76
- when '=' then :zaphod
77
- end
78
- end
79
- else
80
- if @app.nil? || @app.empty?
81
- @app = arg
82
- else
83
- @app += ' ' + arg
84
- end
85
- end
86
- end
87
- if @views.any? and not @app.empty? and @tags.empty?
88
- @tags << "tag_#{rand(1337)}"
89
- end
90
- else
91
- @app = command
92
- end
93
- end
94
- end
95
- @command = command
104
+ def add_tag arg
105
+ @tags << arg[1..-1]
106
+ end
107
+
108
+ alias :add_view :add_tag
109
+
110
+ def add_mode arg
111
+ modes = RE_MODES.match(arg).to_s.split('')
112
+ @modes += modes.split.map do |mode|
113
+ MODES[mode]
96
114
  end
115
+ end
97
116
 
98
- def web_search search_string, engine = :google
99
- escaped_string = URI.escape search_string
100
- case engine
101
- when :duckduckgo then escaped_string.prepend "https://duckduckgo.com/?q="
102
- else escaped_string.prepend "https://www.google.com/#q="
103
- end
104
- URI.parse escaped_string
117
+ def set_app arg
118
+ if @app.nil? || @app.empty?
119
+ @app = arg
120
+ else
121
+ @app += ' ' + arg
105
122
  end
123
+ end
106
124
 
107
- def find_browser
108
- begin
109
- if @browser.nil?
110
- Subtlext::Client.all.each do |c|
111
- if c.klass.match(@@RE_BROWSER)
112
- @browser = c
113
- @view = c.views.first
114
- return
115
- end
116
- end
117
- end
118
- rescue
119
- @browser = nil
120
- @view = nil
125
+ def find_browser
126
+ begin
127
+ if @browser.nil?
128
+ Subtlext::Client.all.each do |c|
129
+ if c.klass.match(RE_BROWSER)
130
+ @browser = c
131
+ @view = c.views.first
132
+ return
133
+ end
121
134
  end
135
+ end
136
+ rescue
137
+ @browser = nil
138
+ @view = nil
122
139
  end
140
+ end
123
141
 
124
- def execute
125
- case @command
126
- when String
127
- if $subtle
128
- subtle_execute
129
- else
130
- command = "#{@command} &>/dev/null"
131
- puts command if $debug
132
- system command
133
- end
134
- when URI
135
- command = "xdg-open '#{@command.to_s}' &>/dev/null"
136
- puts command if $debug
137
- system command
138
- if $subtle
139
- browser = find_browser
140
- browser.focus unless browser.nil?
141
- end
142
- end
143
- true
142
+ def execute
143
+ case @command
144
+ when String
145
+ if $subtle
146
+ subtle_execute
147
+ else
148
+ command = "#{@command} &>/dev/null"
149
+ puts command if $debug
150
+ system command
151
+ end
152
+ when URI
153
+ command = "xdg-open '#{@command.to_s}' &>/dev/null"
154
+ puts command if $debug
155
+ system command
156
+ if $subtle
157
+ browser = find_browser
158
+ browser.focus unless browser.nil?
159
+ end
144
160
  end
161
+ true
162
+ end
145
163
 
146
- def subtle_execute
147
- if $debug
148
- puts "App: #{@app}"
149
- puts "Tags: #{@tags.to_s}"
150
- puts "Views: #{@views.to_s}"
151
- puts "Modes: #{@modes.to_s}"
152
- end
153
- tags = @tags.map do |t|
154
- tag = Subtlext::Tag.first(t) || Subtlext::Tag.new(t)
155
- tag.save
156
- tag
157
- end
158
- @views.each do |v|
159
- view = Subtlext::View.first(v) || Subtlext::View.new(v)
160
- view.save
161
- view.tag(tags) unless view.nil? or tags.empty?
162
- end
163
- unless (client = Subtlext::Client.spawn(@app)).nil?
164
- client.tags = tags unless tags.empty?
165
- client.flags = @modes unless @modes.empty?
166
- end
167
- true
164
+ def subtle_execute
165
+ if $debug
166
+ puts "App: #{@app}"
167
+ puts "Tags: #{@tags.to_s}"
168
+ puts "Views: #{@views.to_s}"
169
+ puts "Modes: #{@modes.to_s}"
170
+ end
171
+ tags = @tags.map do |t|
172
+ tag = Subtlext::Tag.first(t) || Subtlext::Tag.new(t)
173
+ tag.save
174
+ tag
175
+ end
176
+ @views.each do |v|
177
+ view = Subtlext::View.first(v) || Subtlext::View.new(v)
178
+ view.save
179
+ view.tag(tags) unless view.nil? or tags.empty?
180
+ end
181
+ unless (client = Subtlext::Client.spawn(@app)).nil?
182
+ client.tags = tags unless tags.empty?
183
+ client.flags = @modes unless @modes.empty?
168
184
  end
185
+ true
186
+ end
169
187
  end
@@ -7,6 +7,7 @@ class Menu
7
7
 
8
8
  attr_accessor :style
9
9
  attr_writer :name
10
+ attr_writer :path
10
11
 
11
12
  def initialize name
12
13
  self.name = name
@@ -15,10 +16,15 @@ class Menu
15
16
  set_item(Editor.new self) unless self.is_a? Dynamic
16
17
  end
17
18
 
19
+ def path
20
+ @path ||= '$PATH'
21
+ end
22
+
18
23
  def encode_with coder
19
24
  coder['name'] = @name
20
25
  coder['items'] = items
21
26
  coder['style'] = style
27
+ coder['path'] = path
22
28
  end
23
29
 
24
30
  def init_with coder
@@ -26,6 +32,7 @@ class Menu
26
32
  @items = coder['items']
27
33
  self.style = coder['style']
28
34
  set_item(Editor.new self)
35
+ self.path = coder['path']
29
36
  end
30
37
 
31
38
  def set_item item
@@ -32,7 +32,7 @@ class Run_Menu < Menu
32
32
  super items, self.name
33
33
  end
34
34
 
35
- def get_files dirs = (`echo $PATH`).split(':')
35
+ def get_files dirs = `echo #{path}`.split(':')
36
36
  @files = []
37
37
  dirs.each do |dir|
38
38
  get_files_rec dir
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynmenu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joakim Reinert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-08 00:00:00.000000000 Z
11
+ date: 2013-07-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A dmenu wrapper for subtle wm
14
14
  email: mail@jreinert.com
@@ -17,15 +17,15 @@ executables:
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - lib/history.rb
20
21
  - lib/item.rb
21
22
  - lib/editor.rb
22
23
  - lib/style.rb
24
+ - lib/dynamic.rb
23
25
  - lib/menu.rb
24
- - lib/root_menu.rb
25
26
  - lib/run_menu.rb
26
- - lib/history.rb
27
- - lib/dynamic.rb
28
27
  - lib/command.rb
28
+ - lib/root_menu.rb
29
29
  - bin/dynmenu
30
30
  homepage: https://github.com/supasnashbuhl/dynmenu
31
31
  licenses: []
@@ -47,9 +47,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - dmenu
49
49
  rubyforge_project:
50
- rubygems_version: 2.0.0
50
+ rubygems_version: 2.0.6
51
51
  signing_key:
52
52
  specification_version: 4
53
53
  summary: Dynmenu
54
54
  test_files: []
55
- has_rdoc: