20130517

RatPoison and You


I've spent some time on my RatPoison configuration. At first I was quite daunted by having nothing in front of me but a blank screen and a few keyboard shortcuts that I had yet to learn. Unfortunately the documentation on the main RatPoison site is pretty sparse, so much of what I learned was from guesswork and dumb luck. The main reason for installing RatPoison on my laptop was because I use my laptop for very little more than irssi and ssh, so obviously the terminal was a big deal. At first I decided to try Eterm, as I have used it a lot in the past and I am quite a big fan. However, I was unable to get it to run borderlessly in RP, so instead I went with rxvt-unicode, which is basically the rxvt terminal with UTF-8 support. After trying it out I was very impressed and it is now my default terminal. The first thing I looked into was setting up my ~/.Xdefaults file so I could have my usual green on black theme (because it makes me feel like I'm in the Matrix):
urxvt.background: black
urxvt.foreground: green
urxvt.scrollBar: false
urxvt.buffered: true
urxvt.font: xft:Terminus:pixelsize=9:antialias=false
urxvt.boldfont: xft:Terminus:bold:pixelsize=9:antialias=false
That is my ~/.Xdefaults file, the first two lines tell the terminal what background and foreground colours to use, the third line gets rid of the scrollbar, because having a scrollbar in my overall RP look would totally harsh my vibe, and the fourth line enables buffering (and yes, I did type "buggering" there by accident). The last two lines set the font and size. I am using Terminus at 9px because I have super-human eyesight. Terminus is not my first choice for a monospace font, however it is my first free choice, as my favourite monospace font is Microsoft's Consolas.

(Edit: There is now an open-source version of Consolas called "Inconsolata", which is absolutely brilliant. Check it out here)

Once I had my terminal looking how I wanted it to, I moved on to my /etc/ratpoisonrc file so that I could set up some keybindings as well as my default terminal:

alias term exec urxvt
escape C-f
warp off
startup_message off
set winname class
defborder 0
set padding 0 0 0 0
defbarpadding 0 0
exec xsetroot -solid \006060 -cursor_name left_ptr
bind semicolon colon
set bgcolor black
set fgcolor green
set font -xos4-terminus-*-*-*-*-16-*-*-*-*-*-iso8859-15
set bargravity sw
As you can see, I set urxvt as my default terminal, and I also set some padding and border options. I also set the background and foreground colours to black and green respectively so as to match my terminal theme. The last line sets the RatPoison "infobar" to display on the bottom left corner.

As for my key bindings, I changed the default escape key from ctrl-t to ctrl-f, this is because I swapped my ctrl and capslock keybindings in my xorg.conf so that I would save myself some carpal tunnel syndrome. Obviously, on a qwerty keyboard, typing ctrl-f is more economical than ctrl-t when your capslock key is actually your ctrl key. I also set up some other key bindings for other programs I might use regularly:

bind f exec firefox
bind m exec urxvt -e alpine
bind u exec urxvt -e irssi -n Kasyx
bind r restart
bind Delete exec sudo /sbin/shutdown -h now
bind c exec urxvt
bind l exec xlock -mode blank
bind d exec ratpoison -c "echo `date`"
bind q remove
bind p exec urxvt -e elinks
When it comes to using the bindings in RatPoison, one must first press the escape sequence, in this case ctrl-f, thus if I wanted to open Firefox, I would type ctrl-f followed by the letter f. Other keybindings worth mention are alpine; the application I use to read my email, irsii; my IRC client of choice and urxvt; my terminal. I have also set up a keybinding on d, which will pop up the date and time in the "infobox" mentioned earlier.

The finished product:



The image is blurred there because I don't want you reading my email subject lines. In this screencap, you can see that I have split my screen into 3 sections; 2 on the bottom horizontal split, and 1 on the top. The top frame currently has an instance of alpine running, however that frame is used for various other things such as Firefox, work in the terminal and so on. The bottom left frame is for irssi where I am currently berating Calvin over his love of Emacs. The bottom right frame is a permanent terminal session wherein I am usually ssh'd into my firewall - cerberus (as you can see by the sexy log in message).

I will leave it at that for this article as it is already running a bit on the long side, so in my next article I will discuss the configuration of my ~/.bashrc file.

Pimp my .bashrc


To your average pleb, the ~/.bashrc file is pretty worthless. However to sysadmins and *nix geeks alike, it is a thing of great importance, and there are many who spend hours upon hours getting it just right. I am one of those people. For me, the bash prompt itself is very important as it is what I am going to see every time I hit enter in my terminal. I'm going to try and keep this brief (although I doubt I will), so without further ado, here is my current bash prompt:



As you can see, I am using a multi-line prompt. The first line, in order, shows my user@host, my current working directory and my bash history number. The second line shows my command number and my effective UID. The general ascii prettiness was achieved through putting the terminal into line-drawing mode.

function prompt {
Black="\e[30m" 
Red="\e[31m"

Green="\e[32m"
LightGreen="\e[32;1m" 
Blue="\e[34m"
 
LightBlue="\e[34;1m"
 
NC="\e[0m" # No Color

PS1="\[$LightGreen\033(0\154\033(B\][\[\033(0\161\161\033(B$Green\][\[$Red\]\u@\h\[$Green\]]\[\033(0\161\033(B\][\[$Red\]\w\[$Green\]]\[\033(0\161\033(B\][\[$Red\]\!\[$Green\]]\[\033(0\161\161\033(B\]]\n\[$LightGreen\033(0\155\161\033(B$Green\][\[$Red\]\#\[$Green\]]\[\033(0\161\033(B\][\[$Red\]\$\[$Green\]]\[\033(0\161\161\033(B\][\[$NC\]"
PS2="> " 
}
 
prompt
It may seem pretty complicated, but once you get the hang of it, it really isn't too hard to figure out:

\033(0 puts the terminal in line-drawing mode, and then \033(B takes it out of it. This means that by putting certain numbers between those sequences, you can make some rather pretty shapes. For a full list of characters and their numerical representations, check out this guide.

Here is a full list of the escaped characters and what they do:

If you look at the line of code defining the variable PS1, you will see a few of these escaped characters in there. You will also see a number of different colour variables. These variables are defined at the top of the file, because typing out \e[30m just to change the following text to black is pretty annoying. Thus I created a variable for each colour enabling me to just type $Black instead.

Sifting through the mess of characters defining the PS1 variable, you will also find a lot of \[ and \] escapes. These are to define non-printing characters so that you don't completely fuck over your word wrapping. Pretty much anything that does not move the cursor forward is a non-printing character (colour codes, escaped keys, etc.). I found adding those to be invaluable as my terminal window isn't always the same size, so if I happen to use a terminal in one of the smaller frames in RatPoison, it would render horribly if I didn't use those escape sequences to delimit my non-printing characters.

This took me quite a while to get just right, and I think it's a pretty fun gimmick and something to mess around with when you just absolutely have nothing. else. to do.

autoreply.pl Conundrum


A while ago, I posted a question in the Linux Section of MyBroadband about email autoreplies (as set in /etc/aliases) using the autoreply.pl script (which I believe comes with Webmin?).

Anyhow, the issue was that if one user had an autoreply set on their email, and they were included via CC or BCC in an email to one or more other users, the auto reply would respond to the original sender listing the "From" header as the address of the user the original email (the email to which the auto reply is now replying) listed first in the "To" header. I could probably word that better, but I'm not going to. Obviously, this causes issues as if steve@foo.bar sends an email to jim@foo.bar CC'ing fred@foo.bar, and Fred has an auto reply set up, then Steve will get Fred's autoreply, only it will seem like it was sent from Jim, thus leading Steve to believe Jim is away, drive over to Jim's house, sleep with Jim's wife, only to have Jim arrive home from work and bludgeon Steve to death with a SCSI cable. Needless to say, this is not something the more "vigilant" sysadmin would want (have you ever tried to clean blood off a SCSI cable?).

After some poking about, I realised that this autoreply nonsense would only happen if there were forward aliases set up in /etc/aliases. i.e. if "fred@foo.bar" was forwarding to "fred.fredson@foo.bar", etc. That way, if an email was sent to fred@foo.bar, it would then be forwarded to the actual mailbox of fred.fredson@foo.bar which would then send an autoreply, the headers of which would get lost as it was forwarded around. There is a pretty easy way around this, all you have to do is add a line to the top of each user's autoreply file (the file referenced by autoreply.pl where you would write the actual reply to be sent):

From: user@foo.bar


Obviously, you would replace "user@foo.bar" with the user's email address. This would ensure that when the autoreply is sent, the From header remains unchanged, regardless of how many times it is forwarded, aliased, marked as spam, released from quarantine and ignored by the original sender.

I realise I am probably the only person to ever actually deal with this problem, but hell, maybe someone else out there may benefit from a link to this blog appearing in their Google search.