This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: A Few Wmii-3 Hacks
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
I’m all hot in the collar over this as well. Totally lovestruck. They took all the right cues from Plan 9. I’ve been enjoying Mauricio’s script. Here’s a couple minor hacks.
PLEASE NOTE: Mauricio’s hacks (and mine) only work with the stable wmii-3 just released.
Resizing Hotkeys
I don’t ever swap two windows. So I used those hotkeys for pushing the edges of a window wider. For example, Alt+Control+k adds 48 pixels to the right side of a window. Now, if that window is up against the right-hand side of the screen, this’ll have no affect.
I don’t use the numeric tags. I use about ten verbose tags and wmii-3 displays them in order in the bar. So I use the numeric keys to tab quickly between them. (Alt+1 is the first tag, Alt+2 is the second…) I got this from Suraj N. Kurapati (who also posted his Ruby wmiirc.
I’ve also added Alt+Shift+num which adds the tag at num position to the current window’s set of tags. And Alt+Control+num removes the tag at num position from the current window’s set.
(0..9).each do |i|
k = (i - 1) % 10
on_key("#{MODKEY}-#{i}") do
view(read('/tags').split[k] || i)
end
on_key("#{MODKEY}-Shift-#{i}") do
key = read('/tags').split[k] || i
oldtags = read("/view/sel/sel/tags").split(/\+/)
write "/view/sel/sel/tags", (oldtags + [key]).uniq.join("+")
end
on_key("#{MODKEY}-Control-#{i}") do
key = read('/tags').split[k] || i
oldtags = read("/view/sel/sel/tags").split(/\+/)
write "/view/sel/sel/tags", (oldtags - [key]).uniq.join("+")
end
end
Action Commands
Mauricio lets you setup some commands in your Ruby script which you can get to from the menu. For example, Alt+a google launches a search in your browser using the current cursor selection as the search terms. I’ve just extended this a bit by allowing the search terms right on the bar. So: Alt+a google houyhnhnms.
on_key("#{MODKEY}-a") do
internal_actions = {
"browser" => lambda do |selection|
selection ||= `wmiipsel`.strip
case browser = ENV["BROWSER"]
when nil: system "/etc/alternatives/x-www-browser '#{selection}' &"
else system "#{browser} '#{selection}' &"
end
end,
"google" => lambda do |*selection|
require 'cgi'
if selection
selection = CGI.escape(selection.join(" "))
else
selection = CGI.escape(%!"#{`wmiipsel`.strip}"!)
end
url = "http://www.google.com/search?q=#{selection}"
case browser = ENV["BROWSER"]
when nil: system "/etc/alternatives/x-www-browser '#{url}' &"
else system "#{browser} '#{url}' &"
end
end
}
wmiimenu((action_list + internal_actions.keys).sort) do |choice|
if internal_actions[choice]
internal_actions[choice].call
else
choices = choice.split(/\s+/)
if internal_actions[choices.first]
internal_actions[choices.shift].call(*choices)
end
system("$HOME/.wmii-3/#{choice} &") if /^\s*$/ !~ choice
end
end
end
For some other shell snippets: snippets. And, for more about tagging: tagging.