A prettier Terminal in OS-X Part 3 (urxvt and screen)

I was a bit annoyed of having to set TERM=xterm-256color. A more or less proper solution can be found on the rxvt-unicode ml from John Eikenberry.

cd ~
infocmp -L rxvt-unicode > rxvt-unicode.terminfo
sed -i '' 's/#256/#32767/' rxvt-unicode.terminfo
sed -i '' 's/#88/#256/' rxvt-unicode.terminfo
if [ ! -e .terminfo ]; then
mkdir .terminfo
fi
tic -o .terminfo/ rxvt-unicode.terminfo
rm rxvt-unicode.terminfo

I’ve also largely assimilated Bart’s configs. You can find them and the screenrc here .

hf

A prettier Terminal in OS-X Part 2 (urxvt and more awesomeness)

Update: thanks to Sung Pae you don’t need to rename perl, you can just set the environment variable:
    PERL=/usr/bin/perl ./configure --foo --bar ...

Update2: you also no longer need the system perl at all along with the double free patch. since my own macosx-clipboard got released with urxvt 9.07 see the changelog here it does depend on Mac-Pasteboard though.

Last time I explained a bit on how to get awesome going. There is a few tuning settings you can do for better awesome usage…

First of all I like the snap font frome the artwiz package for my title bar:

mkdir ~/.fonts
wget http://www.flyingseagull.de/blog/assets/artwiz-aleczapka-en-1.3.tar.bz2
tar xjvf artwiz-aleczapka-en-1.3.tar.bz2
mv artwiz-aleczapka-en-1.3/snap.pcf ~/.fonts
fc-cache -fv ~/.fonts

Second you might like to have the right apple key as mod and the left one as alt. That way you can have awesome use it’s hotkeys using mod2 and have programs like irssi hook the left apple key as alt while letting your option key work for apostrophes and the like. Note that I use us dvorak as default layout and thus don’t have äöü etc. directly on the keyboard… So YMMV and you might want to adjust the following to your needs. I use the following in my ~/.xmodmap

! left apple key becomes alt 
! and right one stays meta
clear mod1
clear mod2
keycode 71 = Alt_L
add mod2 = Alt_L
keycode 63 = Meta_L
add mod1 = Meta_L

I have attached my Xdefaults and awesomerc. After disabling the “Enable key equivalents under X11” in Xquartz preferences you can bind awesome keys the way you want them. With my config, leaving X11 would be apple-shift-w. The reason I don’t use Apple-Q is that there is no prompt on exit and in very rare cases the Apple-Q gets passed through from another app you close on top of Xquartz. Apple-W properly closes windows and so on. You should just check the config for the hotkeys.

Oh and don’t forget to do a:

sed -i '' 's/timebomb/YOURUSER/g' ~/.Xdefaults

if you decide to use my Xdefaults.

You should also disable the xterm autolaunch in Xquartz. As the UserFAQ states the following should do the trick:

defaults write org.x.X11 app_to_run /usr/bin/true

Personally I use terminus-font for coding and terminal activity. You can install it with:

sudo port install terminus-font

Again, you might, or might not like it, in which case you will probably like to change your terminals font in the Xdefaults after copying it to ~/.Xdefaults.

Now if you look at my past post, I launch urxvtd in my xinitrc and my awesomerc refers to urxvtc and you might wonder wtf is does, as I did. Well, basically it will just launch one urxvt daemon and many clients. That way the memory usage gets cut down by a lot and the launch times drop a lot too.

Now there is a little issue with urxvt in osx. If you install it through macports it will use macports perl. Why is that such a problem? As far as I know it doesn’t include the obj-c bindings. Which means that you won’t be able to copy and paste without mouse or shift-insert(which wouldn’t be such a problem if we had insert keys on our mac keyboards). I admit there is other ways to handle it, but I settled with the following solution… Basically all you do is compile urxvt with stock perl and patch it.

Before you do the thing below you will probably want to backup ports perl5

#!/bin/sh

mv /opt/local/bin/perl5 /opt/local/bin/perl5bak
ln -s /usr/bin/perl /opt/local/bin/perl5
wget http://dist.schmorp.de/rxvt-unicode/rxvt-unicode-9.06.tar.bz2
tar xjvf rxvt-unicode-9.06.tar.bz2
cd rxvt-unicode-9.06
patch -p1 < doc/urxvt-8.2-256color.patch
patch -p0 < ../rxvtperl-objc-doublefree.diff
./configure --prefix=/opt/local --enable-xterm-colors=256
find . -name Makefile -exec sed -i '' 's/-arch ppc//g' '{}' \;
cd src 
make install
cd ../doc
make install
mv /opt/local/bin/perl5bak /opt/local/bin/perl5

Of course you need to replace ppc with i386 on a g4. Stock perl will make the configure try to build urxvt as universal build and fail (rxvtperl-objc-doublefree.diff is available here).

You might wonder why the double free patch is not included in the distribution of urxvt. Well apparently it’s not that common. I haven’t tried it on other systems, but it seems to be only happening when the objc bridge is loaded in urxvt(i.e. the macosx-clipboard plugin included in urxvt).

Another nice thing I use in urxvt is Barts url-yanking plugin. You can change the hotkeys in the Xdefaults I posted above. Just copy mark-and-yank into ~/.urxvt and you’re set. Basically I can cycle through urls in my console with M-U and launch them in the default browser upon pressing enter…. nifty!

Proper snippets for vim... wooohoooo!

For a very long time vim has had only snippets plugins, which were using nasty regex hacks to get TextMate like snippets going…

Also related to the fact that vim for example does not move marks when you do any editing action. I.e. try putting a mark on a specific position in vim, then start deleting in front of the mark and the mark will still stay on the same column. Thus it’s not really trivial to track where the next position of the snippet should start when you want to jump to it.

The solution found in most snippets plugins for vim is to use a region like <++> and to search for it on your snippet expansion trigger key. Imaps, snippetsemu all do it that way. While snippetsEmu used to be the closest to TextMate behavior it was also the most buggy.

On a sidenote vim actually does movement of marks when you join two lines with mark_col_adjust, but I found it to be far from trivial to just make all editing operations, have that behavior on marks. Anyway, now there’s a new contender called snipMate. It actually no longer relies on that regex expansion described above and from what I can tell it’s pretty nifty.

I suggest you give it a try. Here’s a comment on how it works by the author:

00:14 [  meese ] timebomb: well essentially, each snippet is stored
as a string with each tab stop being specified by "${1}", "${2}", etc., 
which are removed once the snippet is expanded. Before that, though, 
the plugin stores the position of each "${1}" according to its position
on the line in a list, and the count of "\n"'s before that to determine
which line number it's on via some regexes; then it keeps track of 
your position by updating the list each ti

On a side note the latest version properly honors expandtab options, however still reading the ts option, there’s a little fix below, but I bet Michael will incorporate it later today.

@@ -214,7 +214,7 @@
                let i += 1
            endw
            " expand tabs to spaces if 'expandtab' is set
-            if &et | let snippet = substitute(snippet, '\t', repeat(' ', &ts), 'g') | en
+            if &et | let snippet = substitute(snippet, '\t', repeat(' ', &sts), 'g') | en

            let snip = split(substitute(snippet, '$\d\|${\d.\{-}}', '', 'g'), "\n", 1)
            if afterCursor != '' | let snip[-1] .= afterCursor | en

Anyway, rock on. Happy vimming, I bet you’ll enjoy it.