Add shorthand for define_method

pull/1/head
Takashi Kokubun 8 years ago
parent 55e172e895
commit ea07739f6c

@ -0,0 +1,19 @@
define :activate do |query, options = {}|
command = options[:command] || query
execute(<<-SHELL)
match=$(wmctrl -l | grep "$(hostname) #{query}")
case $? in
1)
#{command}
;;
0)
window_id=$(echo $match | tail -n1 | cut -d' ' -f1)
wmctrl -i -R $window_id
;;
esac
SHELL
end
remap 'C-o', to: activate('Nocturn', command: 'nocturn')
remap 'C-u', to: activate('.*Google Chrome$', command: 'google-chrome-stable')
remap 'C-h', to: activate('urxvt')

@ -9,4 +9,5 @@ MRuby::Gem::Specification.new('xkremap') do |spec|
spec.add_dependency 'mruby-io', mgem: 'mruby-io'
spec.add_dependency 'mruby-process', mgem: 'mruby-process'
spec.add_dependency 'mruby-onig-regexp', mgem: 'mruby-onig-regexp'
spec.add_dependency 'mruby-shellwords', mgem: 'mruby-shellwords'
end

@ -38,6 +38,10 @@ module Xkremap
key
end
def define(name, &block)
ConfigDSL.define_method(name, &block)
end
private
def compile_exp(exp)

@ -29,7 +29,7 @@ module Xkremap
when :release
Proc.new { XlibWrapper.release_key(@display, to.keysym, to.modifier) }
when :execute
Proc.new { system("nohup #{to.command} >/dev/null 2>&1 &") }
Proc.new { system("nohup /bin/sh -c #{to.command.shellescape} &") }
else
raise "unexpected action: #{to.action.inspect}"
end

Loading…
Cancel
Save