Monday, June 17, 2013

Bash history made better

The following can be used to set up a much more useful bash history search. Simple to set up, it basically gives you the "ctrl-r" style command search simply by pressing the up button. 

Eg: Typing $ vim and pressing the up arrow will return all commands that start with vim. So simple, so powerful.

Setup:

$ cd ~
$ touch .inputrc

Add the following to .inputrc

"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on

That's it! Now you have awesome history search.

Monday, May 06, 2013

Good bye Unity, hello Xmonad

About 8 months ago I began working on a Ruby project and as a result made the switch from Windows to Linux as my daily driver OS. This is something I've been wanting to do for a while but up until now the project I've been working on have necessitated a Windows box. 

Once I got my head back into the Linux world I loved it. I can't see myself going back, however, I did developed a healthy distaste for Unity (which seems to be par for the course). Co-workers of mine were using Xmonad and during the downtime I decided to give it a go. 

It's the best. 

It took me about half a day to get my head around how it really worked, but now that I have I found other OSs clumsy in the extreme. This is especially true if your working on the command line a lot or working with tools such as a Vim or emacs. In fact, that's not even quite true, even if you aren't working with the command line a lot it's great, but working with terminal so much nicer with Xmonad that I think you'll find yourself doing it more. 

Hyperbole aside, the one thing about Xmonad is that it isn't exactly trivial to set up. So I'll try and out line as simply as possible the steps I went through to get mine working. 

First up, I'm using Ubuntu 12.04 (Percise). No guarantees these instructions will work on earlier or later versions.


Install

Use apt-get to install both xmonad and added plugin called gnome-panel (you'll need this if you are running a gnome/xmonad session).

$ sudo apt-get install xmonad
$ sudo apt-get gnome-panel

At this point xmonad will be installed but you'll need to log out to change the session. Before you log back in select the window manager using the button on the top right hand corner of the login box. Choose "Gnome/Xmonad" (or similar).


Configure

Once you're in you'll need to configure things a little. First up you'll probably be greeted with a black screen and nothing else. 

Alt+Shift+Enter opens a new terminal. By default alt is the Meta (mod) key, you can change this later (to Windows key for example).

Create the config:

$ cd ~
$ mkdir .xmonad
$ touch .xmonad/xmonad.hs

Edit the config:
Below is the config I use. You should be able to copy and paste this into your xmonad.hs and it will work.

import XMonad
import XMonad.Util.EZConfig
import XMonad.Hooks.SetWMName

myMod = mod4Mask
myWorkspaces = ["1","2","3","4","5","6","7","8","9"]


main = xmonad $ defaultConfig {   
    modMask = mod4Mask,
    workspaces = myWorkspaces,
    startupHook = setWMName "LG3D"
    }
    `additionalKeysP`
    [("M-x f", spawn "firefox")]


A few points:

  • I set the meta key to windows key by using mod4Mask (mod1Mask is the Alt key)
  • The setWMName call is used to ensure Java Swing apps (such as RubyMine or InterliJ) render correctly.
  • The firefox start is an example of setting up your own application hot keys.

Done!

Now you probably want to look up the Xmonad key combos to find out to do things. It will take a while to get used, but not as long as you think and once you're up and running you'll love it.

Finally a much detailed explanation of all this can be found on the Xmonad Gnome page.