jasonwryan.com

Miscellaneous ephemera…

Archwiki elvis for Surfraw

image

I have been using Surfraw for the better part of eighteen months, and I think that it is a perfect Unix tool: it does one thing, extremely well… If you haven’t come across it, Surfraw is a command-line interface to a couple of dozen repositories of knowledge. It is described thus:

It reclaims google, altavista, babelfish, dejanews, freshmeat, research index, slashdot and many others from the false-prophet, pox-infested heathen lands of html-forms, placing these wonders where they belong, deep in unix heartland, as god loving extensions to the shell.1

The shell scripts that power the searches of the repositories are called elvi, the singular being elvis. Currently, in the git repo, there are over 100 elvi, ranging from Wikipedia through to the CIA website (yes, the project was founded by Julian Assange), Slashdot and The Wayback Machine.

As comprehensive as the list of elvi is, there was one glaring hole. Arch Linux is represented in terms of elvi to search the AUR and the official package repositories, but nothing for the Arch Wiki, perhaps the best GNU/Linux reference wiki on the web.

So I thought I would rectify that.

You can grab the archwiki elvis from my mercurial repo, copy it into your local directory at $XDG_CONFIG_HOME/surfraw/elvi/ or in the system folder at $XDG_CONFIG_DIRS/surfraw/ and you can surf the Arch Wiki, or any one of the nine other language wikis, from the command line.

Surfrawize the soul of your favourite internet wonder. Join the Shell Users’ Revolutionary Front Against the WWW by submitting code. Reclaim heathen lands. Bear witness to the truth. Its love will set you free.

Notes
  1. A bonus: all of the documentation is written like Unix agitprop

Vim Colours in the Console

image

I have spent the last couple of days trying to understand why I couldn’t get Vim to display the correct 16 colours in the console. Not in a terminal emulator in X, like xterm or rxvt-unicode, but in the consoles, TTY1-6.

After a lot of searching, more reading into the arcane documentation of Linux terminals than I was either prepared for or keen on and some experimentation, I have it working. With one caveat; I wasn’t prepared to set the TERM environment in my .vimrc. Apart from being cautioned against, as I do set it for tmux, I was anxious to avoid any clashes when running Vim in tmux (which I do most of the time).

From the top, then. Logging into a console and checking the $TERM and colours, gave me the default:

1
2
3
$ echo $TERM && tput colors
linux
8

Which, under my current configuration of Vim, rendered colours like so:

image

Hardly satisfactory.

The first step was to remove the line in my .vimrc that was forcing 256 colours:

1
set t_Co=256

Then I had to rewrite my colourscheme to change all of the references to the terminal colour numbers to colour names, as apparently that is what 8-colour terms accept. So, my miromiro.vim, went from looking like:

1
2
3
4
hi Normal          ctermfg=15
hi Ignore          ctermfg=8
hi Comment         ctermfg=7
hi LineNr          ctermfg=8

…to the more literal:

1
2
3
4
hi Normal         ctermfg=white    cterm=bold
hi Ignore         ctermfg=black    cterm=bold
hi Comment        ctermfg=grey
hi LineNr         ctermfg=black    cterm=bold

Once I had made the necessary changes, I saved this new colourscheme as miro8.vim1. And, yes, I know I could have included it in an if condition in my original colourscheme2, but I was intent on keeping things compartmentalized until I had it working…

Running Vim in the console was now starting to look promising:

image

The final piece of the puzzle was to pass my X colours to the console. Fortunately, Aaron Griffin’s 2006 post made this a trivial exercise. With the following lines in my .bashrc:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Linux console colors (jwr dark) 
if [ "$TERM" = "linux" ]; then
   echo -en "\e]P0000000" #black
   echo -en "\e]P83d3d3d" #darkgrey
   echo -en "\e]P18c4665" #darkred
   echo -en "\e]P9bf4d80" #red
   echo -en "\e]P2287373" #darkgreen
   echo -en "\e]PA53a6a6" #green
   echo -en "\e]P37c7c99" #brown
   echo -en "\e]PB9e9ecb" #yellow
   echo -en "\e]P4395573" #darkblue
   echo -en "\e]PC477ab3" #blue
   echo -en "\e]P55e468c" #darkmagenta
   echo -en "\e]PD7e62b3" #magenta
   echo -en "\e]P631658c" #darkcyan
   echo -en "\e]PE6096bf" #cyan
   echo -en "\e]P7899ca1" #lightgrey
   echo -en "\e]PFc0c0c0" #white
   clear # bring us back to default input colours
fi

Then it was just a case of setting the relevant colourscheme in my .vimrc:

1
2
3
4
5
if &t_Co < 256
    colorscheme miro8   " colourscheme for the 8 colour linux term
else
    colorscheme miromiro
endif

And you can see a screenshot of the finished product on Flickr.

Notes
  1. miro8.vim

  2. miromiro.vim

Setting Urgent Hints in dwm

image

After nearly 12 months of running a pretty stable dwm, with a consistent patchset (cycle, push, and init pertag1) I finally added another one: statuscolours2

I have been experimenting with WMFS, which is another very nice, minimal tiling window manager and was really enjoying the urgency hints in the status bar, so I decided to patch that functionality into dwm.

Most terminal applications will send a bell when your attention is required; in my case, I was looking for a way to trigger notifications for new mail in mutt or highlights in irssi. In mutt, it was just a case of setting a bell for when mail arrived:

1
set beep_new             # bell on new mail

And in irssi:

1
beep_msg_level = "NOTICE MSGS HILIGHT";

In tmux, to cover all your terminal bases, add:

1
set -g bell-action any # listen for activity on all windows

The next step is to pass those beeps to your terminal. The entry for Urxvt is one I picked up after a quick search turned up this post by rson which had the .Xdefaults line I was looking for:

1
URxvt*urgentOnBell: true

Now, whenever a bell is triggered in irssi or mutt, that is passed to the terminal as an urgent hint. The final step was patching statuscolors into dwm.c to change the tag colour when the hint was received.

You can see my patched dwm.c in my mercurial repo.

Notes
  1. These patches are from the extremely helpful Arch Forum thread: DWM Hackers Unite!
  2. I used a modified statuscolours patch from the suckless mailing list. It irons out the padding issues in the one on the wiki.