Monday 5 January 2009

Njorak isn't dead (yet (now lives on a lone E6400))

Yes, I admit it! I am still a Dvorak typer. I tried going back recently when learning Vim using my new Vim book, but I just can't. Something about Qwerty makes me squirm when trying it. Perhaps it's just that I have become accustomed to the strangeness of Dvorak but in general I don't see any reason to switch back. Sure, I am not that quick when I get in front of someone's Qwerty laptop, but I'll manage.

Now with my new Dell E6400 it's time for yet another njorak layout. Since Swedish characters are too precious to miss out on, but not precious enough to get rid of all the good things about pure and clean Dvorak (hmm, I does sound like a fanatic don't I?). Here it is, the all magical njorak for Dell Latitude E6400 using the Windows key to access Swedish characters.

! njorak, not-quite-dvorak. Version 1.2
! By Pontus Stenetorp
! Derived from us dvorak, accesses Swedish characters through
! altgr or similar combos. Also swaps caps and esc.
! Apply it to an ordinary dvorak keymap using xmodmap.
! Dell Latitude E6400 version
! still dedicated to spatrik

! Set up Swedish special characters
keycode 43 = d D aring
keycode 44 = h H adiaeresis
keycode 45 = t T odiaeresis

! Windows key on a Dell Latitude E6400
keycode 115 = Mode_switch

! Swap escape and caps lock
remove Lock = Caps_Lock
remove Control = Escape
keycode 66 = Escape
keycode 9 = Caps_Lock
add Lock = Caps_Lock
add Control = Escape


I have also added a Caps-lock Escape switch to this version. The reason, there is never a good reason not to remove caps-lock. The only I reason I can come up with is that it's not expected behaviour for anyone who is new to your layout. But being a Vim user (and a Dvorak user, which makes most people perplexed when trying out my keyboard) and also having taken a couple of seconds to ponder on which key I use the most, the switch really is a sane thing to do.

Sunday 4 January 2009

Portssearch alias and portmaster

In order to manage FreeBSD ports I have used portupgrade for some time. It provides neat facilites such as the command portinstall and portupgrade, I am sure that the use of these commands is pretty straight forward. The standard way to install a port is the following.

> cd /usr/ports/category/portname
> make install clean


Instead portupgrade allows you to do.

> portinstall portname

Or

> portinstall category/portname

One problem with portupgrade is that it's written in Ruby. One might argue that this is not really a problem, but when you have a fresh FreeBSD install you don't want to drag in Ruby as your first package. This takes time and you would rather focus on something else.

Luckily there is an alternative that I quite recently stumbled upon. portmaster supports pretty much the same set of operations but is written in shell script. It's quick to install and you are ready to go in a jiffy. It also handles fetching and port configuration first and then starts building and installing.

> portmaster category/portname

The only problem is that it enforces the use of category/portname as arguments. This is most likely to avoid conflicts since the portname might conflict with other portnames. To resolve this portupgrade presents all "likely" matches and asks you to choose from them, portmaster just dismisses your arguments as invalid. I have considered adding this functionality in some way. Perhaps printing "likely" matches and/or conflicts and then terminating would be a good option?

So, now we have a tool to handle port installation with ease. Then we need a way to search for ports when we don't know the actual name or category. There are of course several such tools but out of the box ports supplies the following way.

> cd /usr/ports
> make search name=searchstring


Or if you want to search in dependencies etc. you can always use key instead of name. But this usually give you far too many hits to browse through. But the output even from name is usually a bit too much, listing dependencies, web addresses and maintainers. For example.

> cd /usr/ports
> make search name=hugs98
Port: hugs98-200609_2
Path: /usr/ports/lang/hugs
Info: An interpreter for the functional programming language Haskell 98
Maint: haskell@FreeBSD.org
B-deps: bash-3.2.39_1 bison-2.3_4,1 damageproto-1.1.0_2 fixesproto-4.0 gettext-0.17_1 gmake-3.81_3 inputproto-1.4.2.1 kbproto-1.0.3 libGL-7.0.3 libGLU-7.0.3 libICE-1.0.4_1,1 libSM-1.0.3_1,1 libX11-1.1.3_1,1 libXau-1.0.3_2 libXdamage-1.1.1 libXdmcp-1.0.2_1 libXext-1.0.3,1 libXfixes-4.0.3_1 libXi-1.1.3,1 libXmu-1.0.3,1 libXt-1.0.5_1 libXxf86vm-1.0.1 libdrm-2.3.1 libglut-7.0.3 libiconv-1.11_1 m4-1.4.11,1 pkg-config-0.23_1 xextproto-7.0.2 xf86vidmodeproto-2.2.2 xproto-7.0.10_1
R-deps: damageproto-1.1.0_2 fixesproto-4.0 inputproto-1.4.2.1 kbproto-1.0.3 libGL-7.0.3 libGLU-7.0.3 libICE-1.0.4_1,1 libSM-1.0.3_1,1 libX11-1.1.3_1,1 libXau-1.0.3_2 libXdamage-1.1.1 libXdmcp-1.0.2_1 libXext-1.0.3,1 libXfixes-4.0.3_1 libXi-1.1.3,1 libXmu-1.0.3,1 libXt-1.0.5_1 libXxf86vm-1.0.1 libdrm-2.3.1 libglut-7.0.3 pkg-config-0.23_1 xextproto-7.0.2 xf86vidmodeproto-2.2.2 xproto-7.0.10_1
WWW: http://www.haskell.org/hugs/

Usually I remedy this using grep, but perhaps I could do better with some scripting? I quickly hacked together an alias to add to my cshrc that would allow to simply type.

> portssearch searchstring

For example.

> portssearch hugs
Port: hugs98-200609_2
Path: /usr/ports/lang/hugs
Info: An interpreter for the functional programming language Haskell 98

Port: ohugs-0.5_5
Path: /usr/ports/lang/ohugs
Info: Interpreter for Haskell with object-oriented features


All this with just two lines, an extra line to work around some difficulties with escaping strings.

set AWKSTR='{ if ( $0 ~ /^Info:/ ) { print $0; print ""; } else { print $0; } }'
alias portssearch "make -C /usr/ports search name=\!:1 | grep -E '^(Port|Path|In
fo):' | awk '$AWKSTR'"


The only problem I have encountered so far is when a port lacks a comment in it's Makefile and Info: is left out you end up with some ugly output. Like this.

Port: japanese/diclookup-emacs20
Port: japanese/navi2ch-emacs20
Port: textproc/dictum-emacs22


But it's usually a non-issue. For now, I am happy with portmaster and my little portssearch alias.

For more information on portmaster see http://dougbarton.us/portmaster.html