Customizing wmii
So, I’ve been using wmii since June now. I must say, it the greatest piece of software ever made. It is the reason I completly dropped Windows from my laptop.
Over the past 2 months, me and few members from #chiglug, mainly Luca and Tristan(Luca didnt do shit), have been throwing around some scripts to make our wmii experience even better. Tristan suggested writing a script so that we can select our wireless network from dmenu. Thus, I wrote this simple ruby script to use dmenu, iwconfig, and iwlist to get connected to a wireless network.
#!/usr/bin/ruby
cmd = "sudo ifconfig wlan0 up; sudo iwlist wlan0 scanning |" +
" awk -F '[ :=\"\\n]+' '/(ESS|Qual)/{ printf $3 \" \"} /Addr/{ "+
"printf $6 \":\" $7 \":\" $8 \":\" $9 \":\" $10 \":\" $11 \" \"} /Enc/{ print $4 }'"
asdf = `#{cmd}`
puts asdf
h = Hash.new
tmp = "("
asdf.each_line{|line|
l = line.split(" ")
a = Array.new
#Access Point
a[0] = l[0]
#Name
a[1] = l[1]
#Quality
a[2] = l[2]
#key
a[3] = l[3]
h[a[0]] = a
tmp += "echo \"#{a[1]} #{a[0]} (#{a[2]})\"; "
}
tmp += ")"
val = `#{tmp} | dmenu -b`
ap = val.split(" ")[1]
a = h[ap]
cmd = "sudo dhcpcd -k wlan0; sudo iwconfig wlan0 essid #{a[1]} ap #{ap}; sudo dhcpcd wlan0"
system(cmd)
This requires that sudo does not ask for a password, so some people might have to change it to fit their needs. If you use Network Manager, Tristan wrote a script use Network Manager instead of the wireless tools. Also, I didnt add code to make it ask for a password since the networks I use usually don’t have passwords, but it isnt difficult to do. The main part of tihs script is how dmenu is called. You can use a pipe to communicate with dmenu. It expects that you write a list of text items seperated by newlines to its standard input. The user then selects an item from dmenu, and dmenu will write that item to its standard output.
The next thing to do is to bind $MODKEY-w(or whatever shortcut you want to use) to the wireless script. I put the script in /etc/wmii-3.5/wifi.rb. To bind the shortcut, you need to modify the wmiirc file in /etc/wmii-3.5/wmiirc. Now this part is a little tricky. Make sure that you tell your editor not to expand tabs to spaces. In vim, you can do :set noet. Under the key bindings section, add:
Key $MODKEY-w sh -c /etc/wmii-3.5/wifi.rb &
You really need to be careful here. If you dont use tabs, and the right amount of them, wmii will flip out. So, MAKE SURE TO USE TABS NOT SPACES. Now, reload the wmiirc file by either restarting wmii or type MODKEY-a and selecting wmiirc. Typing MODKEY-w should now bring up a list of wireless networks found on the interface wlan0. It usually takes a few seconds to load since it has to scan for the netorks. If it didnt work, you probably didnt use tabs so your wmii will be acting crazy. You can check to make sure the key was bound by running the command ‘wmiir read /keys’. It should display a list of bound keys, and Mod1-w should be in there.
wmii
wmii is amazing. Thats all the world needs to know for now.
Comments (1)