Code Beautifier Textmate Bundle

September 25th, 2008

Textmate’s indent functionality does a passable job of formatting your code BUT there is a great deal of room for improvement.

Inspired by the Paul Lutus’s ruby beautifier script and Tim Burks’s post on making it into a Textmate bundle I’ve put together a Code Beautifier Textmate bundle

It only supports Ruby at present but does improve upon Textmate’s indent functionality, in particular it is better at indenting multiline statements and cleans up white space.

It’s all hosted on Github so if you want to make improvements then please fork away.

Installation

Run this:

cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/mocoso/code-beautifier.tmbundle.git Code\ Beautifier.tmbundle

Then select ‘Bundles > Bundle Editor > Reload Bundles’ from Textmate’s menus

Screen Textmate Bundle

September 9th, 2008

When working on a rails project I usually have script/server, script/console and autotest all running in GNU Screen. Jamie Flournoy has already described why using GNU screen is better than plain old Terminal Tabs.

I’ve put together a Screen Textmate Bundle to make it easy to configure and open per project screen sessions.

Installation

Run this:

cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/mocoso/screen.tmbundle.git Screen.tmbundle

Set up your screen configuration for a project

Create a .screenrc file in your project directory if you want to specify a particular configuration for your project.

For example for a Ruby on Rails project you might create a .screenrc file in your project directory like this

# Have the server running in screen 1
#
# Stuff is used so that when you exit the stuff-ed program, you drop back
# to the bash shell for that screen instead of immediately exiting that
# screen. This is useful for "^c, up-arrow, enter" restarting of programs.
screen -t server 1
stuff "script/server\012"

# Have autotest running in screen 2
screen -t autotest 2
stuff "autotest\012"

# Have the console running in screen 3 
screen -t console 3
stuff "script/console\012"

# Finally have a command line prompt at the project root in screen 4
screen -t project_root 4

Usage

Use this bundle’s ‘Start Session’ command (ctrl-shift-s) to start (or reconnect to) your project’s screen session.

If you have created a .screenrc file in your project directory then this will be used to initialize the new session.

Update (14th Sep 2008)

On Jonathon Palardy’s suggestion I’ve added a ‘Send to Screen’ command (ctrl-alt-c) that copies selected text (or current line if no selection made) to your project’s screen session. If you have multiple windows open in the session then it will paste to the currently selected window.

CSV templating made easy in Rails

June 27th, 2008

CSV Builder is a simple little Rails (v2.1) plugin that makes it easy to write templates to generate CSV formatted output from your Rails application.

It does this by providing a little bit of plumbing gubbins to make a custom template handler from the FasterCSV gem.

So if you want to export data in CSV format from your rails app then install it like this

sudo gem install fastercsv
./script/plugin install git://github.com/econsultancy/csv_builder.git

This plugin was developed as part of project that I have been working on with Econsultancy.com.

Using Git with subversion: Part II (Practice)

June 27th, 2008

More tips on how to use Git with a Subversion repository to get some of the Git goodness, local branches, stashes and much more, without having to persuade everyone else on your project to migrate to Git

If you don’t already have git installed then see part I (Installation).

Clone you Subversion repository

Make a local clone of your subversion repository to work with.

Warning: Git does not support svn:externals but luckily you vendor everything with piston, don’t you? If not then various people have written up hacks for managing svn:externals none of which are ideal but they will get you started.

Assuming you use a standard Subversion repository layout (with /trunk, /branches etc.) then this is as easy as

git-svn clone http://svn.foo.org/project/trunk

Tweak your local Git repository

There are a couple more things that you should do to the repository before beginning work

Firstly, tell Git about the files that Subversion ignores, using:

git svn show-ignore >> .git/info/exclude

This appears to work for some projects/Subversion installations and not others. If it doesn’t work you’ll need to create .git/info/exclude file in the project and add file patterns to exclude by hand.

Secondly, recreate any empty folders which are required by the project e.g. /log. You need to do this because Git does not track empty directories.

Now you are ready to go.

Get to work

  1. Make your changes

    Make changes to the code base in just the same way as you would with Subversion

  2. Commit your changes to your local master branch

    Unless you have been working with local branches this is easy as.

    git commit -a

    Which will commit all your changes to your local Git repository.

    If you have added or removed files you will also need to use git add or git rm to ensure all your changes are committed.

  3. Update your local repository from Subversion

    git svn rebase

    This brings your local Git repository up to date with the central Subversion repository

    It works just like git rebase in that it rewinds your local commits, applies the latest changes from subversion, and then replays your local commits over the top. If there are merge issues you will be warned about them here.

  4. Push your local commits back into subversion

    git svn dcommit

    This applies each of your local commits in turn to the subversion repository.

  5. Repeat (go back to step 1.)

Further reading

Now you’ve got started here are a couple of good resources for when you get stuck

Best of luck.

Using Git with Subversion: Part I (Installation)

May 26th, 2008

You can use Git with a Subversion repository to get some of the Git goodness, local branches, stashes and much more, without having to persuade everyone else on your project to migrate to Git

Install Git

You need to install git-svn first, with MacPorts this is as easy as

sudo port install git-core +svn +bash_completion

And then to enable bash completion (thanks to Graham Ashton for this tip)

cp /opt/local/etc/bash_completion.d/git ~/.git-bash-completion.sh
echo '[ -f ~/.git-bash-completion.sh ] && . ~/.git-bash-completion.sh' >> ~/.profile
. ~/.profile

And for those without macports here are some installation instructions

TextMate integration

If you use TextMate then install the Git Bundle

And you can set TextMate as the editor for git commit messages by adding the following to ~/.profile

export GIT_EDITOR="mate -w"

Basic git configuration

You should tell git who you are.

git config --global user.name “your name”
git config --global user.email “your.email.address@foo.bar”

If you are on OS X, then tell git to ignore .DSStore files in all your projects.

git config --global core.excludesfile .gitexcludes

And create a file ~/.gitexcludes with ‘.DSStore’ in it.

This all you need to configure but there’s much more you can do with git config e.g. aliases for git commands if you want to save those typing fingers.

Coming soon

Using Git with Subversion - Part II (Practice)