Archive for July, 2008

A nice simple prompt for zsh

July 27, 2008

Recently I switched to zsh, after being a bash user for almost 5 years. I was in love with everything in zsh from day one, except one thing – the default prompt. Although zsh ships with several prompt themes, I didn’t like any of them so I looked around a little bit and constructed my own humble prompt. Here it goes:

PROMPT=’[%n@%m %~]$ ‘

In case you’re wondering what this gibberish means:

%n stands for your username(e.g. bozhidar)

%m stands for the first part of your machine’s hostname(you can use %M for the fully qualified name)

%~ stands for the current directory path with your home dir aliased with an ‘~’ (if you want to see the path in its natural form use %d instead)

All of this strange looking character combinations are called “escape sequences” and they have special significance to zsh. The rest of the characters in the prompt definition are represented literally in the resulting prompt. It looks like this(on my machine):

[bozhidar@drow ~/store]$

If you like it simply put the prompt definition like in your .zshrc file. You may want to put a little bit different version of the prompt in the root user’s .zshrc(if you use root at all that is):

PROMPT=’[%n@%m %~]# ‘

This follows the well established pattern that a normal shell and a root shell should be easily distinguished visually.

Using Emacs for Rails development – The perfect setup

July 19, 2008

Lately, I’ve started digging more and more into Rails, preparing for the start of a Rails powered project. Although there are some IDEs offering decent Rails support(namely NetBeans, Komodo and Aptana Studio) I have always preferred the comfort of Emacs for various reasons. So naturally I embarked on a quest to setup a suitable environment for Rails development in Emacs. After a couple of days of searching and evaluating possible solutions I finally set up a wordy environment. It consists of a couple of components – ruby-mode, ruby-electric, nxhtml-mode and rinari.

As you probably have guessed by now ruby-mode provides support for editing ruby source files. The mode is pretty feature complete and under active development, headed by none other than Matz himself. You can get it from the ruby svn repository. ruby-electric provides auto insertion of closing braces, quotes, ends, etc. It can also the found in the ruby repo. Instructions how to setup both modes can be found here. Although many people recommend adding pabbrev(a mode which provides auto-completion) to the setup, I don’t recommend it – I find the mode mostly annoying and stick to the old school dumb auto-completion with M-/ .

nxhtml-mode is a pretty comprehensive package for web development in general. We need it for its excellent support for erubis templates(.rhtml, .erb.html) and of course xhtml and css.

rinari is a mode for Rails development – it contains rich functionality such as the ability to easily navigate between models, views and controllers in a Rails application amongst other features. Instructions how to set up rinari together with nxhtml-mode can be found on rinari’s home page.

It’s always a good idea to add ecb(the Emacs code browser) to the mix, though this is entirely optional.

I hope you enjoy this setup and it helps boost your Rails productivity in Emacs!