dynmenu 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/dynmenu +0 -1
- data/lib/command.rb +163 -145
- data/lib/menu.rb +7 -0
- data/lib/run_menu.rb +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b0807e826ed4e2b62a3f02414b871c7bd85692c
|
4
|
+
data.tar.gz: 8223c9004a9e0da386be65ab1e981383f23e7153
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f76c72085fba64d0a6c70abdaac03da321ceba564effe171551df5aac7ac78cfed42104eeab2cedc413fef0fccd8e5e037769b9811bd815ce45e66a40f65607
|
7
|
+
data.tar.gz: aba4d0d4449ca58b6c1d36368aaaa9cffa3ebdb0ddcce0d3a22cf122cdde342e1348196f5abe8228739db664664f3a987abe22d4e87059e23ab0377b729ad5b4
|
data/bin/dynmenu
CHANGED
data/lib/command.rb
CHANGED
@@ -3,167 +3,185 @@ require 'uri'
|
|
3
3
|
|
4
4
|
|
5
5
|
class Command
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
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
|
data/lib/menu.rb
CHANGED
@@ -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
|
data/lib/run_menu.rb
CHANGED
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
|
+
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-
|
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.
|
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:
|