Project

General

Profile

unexist.dev

Assorted tidbits and projects

extend_commands.patch

Patch made by 'hg export tip' - Wael Nasreddine, 01/16/2011 07:58 PM

View differences:

ruby/launcher.rb Sun Jan 16 19:47:08 2011 +0100
11 11
#
12 12
# Examples:
13 13
#
14
# subtle wm           - Change to browser view and search for 'subtle wm' via Google
15
# urxvt @editor       - Open urxvt on view @editor with random tag
16
# urxvt @editor #work - Open urxvt on view @editor with tag #work
17
# urxvt #work         - Open urxvt and tag with tag #work
18
# +urxvt              - Open urxvt and set full mode
19
# ^urxvt              - Open urxvt and set floating mode
20
# *urxvt              - Open urxvt and set sticky mode
21
# urx<Tab>            - Open urxvt (tab completion)
14
# g subtle wm           - Change to browser view and search for 'subtle wm' via Google
15
# urxvt @editor         - Open urxvt on view @editor with random tag
16
# urxvt @editor #work   - Open urxvt on view @editor with tag #work
17
# urxvt #work           - Open urxvt and tag with tag #work
18
# nautilus --no-desktop - Open nautilus without the desktop
19
# +urxvt                - Open urxvt and set full mode
20
# ^urxvt                - Open urxvt and set floating mode
21
# *urxvt                - Open urxvt and set sticky mode
22
# urx<Tab>              - Open urxvt (tab completion)
22 23
#
23 24
# http://subforge.org/wiki/subtle-contrib/Wiki#Launcher
24 25
#
......
35 36

  
36 37
# Check for subtlext version
37 38
major, minor, teeny = Subtlext::VERSION.split(".").map(&:to_i)
38
if(2470 > teeny)
39
if(major == 0 and minor == 9 and 2470 > teeny)
39 40
  puts ">>> ERROR: %s needs at least subtle `0.9.2470' (found: %s)" % [
40 41
    $0, Subtlext::VERSION
41 42
   ]
......
53 54
module Subtle # {{{
54 55
  module Contrib # {{{
55 56
    # Precompile regexps
56
    RE_COMMAND  = Regexp.new(/^([+\^\*]*[A-Za-z0-9_-]+)([ ][@#][A-Za-z0-9_-]+)*$/)
57
    RE_MODES    = Regexp.new(/^([+\^\*]*)([A-Za-z0-9_-]+)/)
57
    RE_COMMAND  = Regexp.new(/^([+\^\*]*[A-Za-z0-9_\-\/'"\s]+)(\s[@#][A-Za-z0-9_-]+)*$/)
58
    RE_MODES    = Regexp.new(/^([+\^\*]*)([A-Za-z0-9_\-\/'"\s]+)/)
59
    RE_SEARCH   = Regexp.new(/^[gs]\s.*/)
58 60
    RE_URI      = Regexp.new(/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix)
59 61
    RE_CHROME   = Regexp.new(/chrom[e|ium]|iron/i)
60 62
    RE_FIREFOX  = Regexp.new(/navigator/i)
......
219 221
          @candidate = URI.parse(string)
220 222

  
221 223
          info("Goto %s" % [ @candidate.to_s ])
224
        elsif(RE_SEARCH.match(string))
225
          @candidate = URI.parse("http://www.google.com/#q=%s" % [
226
             URI.escape(string.gsub(/^[gs]\s/, ''))
227
          ])
228

  
229
          info("Goto %s" % [ @candidate.to_s ])
222 230
        elsif(RE_COMMAND.match(string))
223 231
          @candidate    = string
224 232
          @parsed_tags  = []
......
233 241
              when "@" then @parsed_views << arg[1..-1]
234 242
              when "+", "^", "*"
235 243
                app, @parsed_modes, @parsed_app = RE_MODES.match(arg).to_a
236
              else @parsed_app = arg
244
              else
245
                if @parsed_app.empty?
246
                  @parsed_app += arg
247
                else
248
                  @parsed_app += " " + arg
249
                end
237 250
            end
238 251
          end
239 252

  
......
259 272
          else
260 273
            info("Launch %s%s" % [ modes2text(@parsed_modes), @parsed_app ])
261 274
          end
262
        else
263
          @candidate = URI.parse("http://www.google.com/#q=%s" % [
264
             URI.escape(string)
265
          ])
266

  
267
          info("Goto %s" % [ @candidate.to_s ])
268 275
        end
269 276
      end # }}}
270 277

  
......
499 506
  Subtle::Contrib::Launcher.run
500 507
end
501 508

  
502
# vim:ts=2:bs=2:sw=2:et:fdm=marker
509
# vim:ts=2:bs=2:sw=2:et:fdm=marker