Is Your Bash Prompt Cramping Your Style?

It is sometimes hard to form a mental model of a directory tree when working with the command line. GUI shells tend to provide more visual cues. For example, in OS X, the Finder has a column view that allows you to quickly see how directories are nested.

Finder column view showing nested directories

So, like a lot of Bash users, I used to get around this by printing the current working directory in my shell prompt:

Directory structure printed in Bash prompt

However, things can get pretty cramped when dealing with deeply nested directories. A better solution is needed. Ideally, I want a minimal prompt that just displays my user@host. I only need to get my bearings when I’m moving around in the directory tree. Therefore, I’ve come up with the following.

Directory structure printed after every cd.  Bash prompt no longer prints current working directory.

The current working directory is printed after every cd. This allows me to get my bearings when I need to, while keeping my Bash prompt short and sweet. The following incantation in ~/.bashrc does the trick:

# Print working directory after a cd.
cd() {
    if [[ $@ == '-' ]]; then
        builtin cd "$@" > /dev/null  # We'll handle pwd.
    else
        builtin cd "$@"
    fi
    echo -e "   \033[1;30m"`pwd`"\033[0m"
}

Have you come up with other solutions for longpromptitis? Let me know in the comments!

Full Post + Comments

Recent Collaboration: Classic Albums Live

I recently collaborated with my friend Daniel Brouse on a website for Classic Albums Live. Daniel did the design and most of the markup while I did the dev bits.

Classic Albums Live gives audiences the opportunity to hear some of their all-time favourite albums live on stage, performed by outstanding musicians in venues around Australia.

Classic Albums Live Homepage

The website allows users to sign up and vote for their favourite albums. I use the Last.fm web service to provide auto completion for the album search. The user drags and drops albums to order her votes.

Voting Interface

Classic Albums Live can then view which albums are popular among their audience.

Admin stats for popular albums

Users can view upcoming tours, read artist and creative bios, and check out the show dates. The site supports custom themes for each tour. Each tour is essentially a mini sub site.

Tour sub site homepage

Tour sub site - about page

Tour sub site - tickets

I built a simple content management system so that Classic Albums Live can manage the tour and site contents.

Admin CMS

The gallery module supports image cropping, and user-defined aspect rations. The site does automatic image resizing and caching of resized images. The client only has to worry about uploading and cropping their images. The site will generate appropriately sized images whenever they are needed on the front end.

Gallery admin

The blog is pretty standard as far as blogs go. It supports post creation and archival, guest and member comments, comment approval and moderation, and tags.

Blog post with comment

Blog admin - comment management

The membership system allows Classic Albums Live to manage the website’s users. The site integrates with Campaign Monitor for mailing lists.

User management

Is there a classic album that you would like to hear live? Let Classic Albums Live know!

Full Post + Comments

John Siracusa on Snow Leopard

John Siracusa on OS X Snow Leopard:

Got all that? A nearly two-year development cycle, but no new features. Major new frameworks for developers, but few new bugs. Significant changes to the core OS, but more reliability. And a franchise rejuvenation with few user-visible changes.

It’s enough to turn a leopard white.

Full Post + Comments

Moving a virtual machine from VMWare Fusion to VMWare Server

I am running VMWare Fusion 2.0.x at home, and VMWare Server 2.0.x on my Ubuntu workstation at work. I wanted to move a virtual machine created on VMWare Fusion to VMWare Server.

Some gotchas that I’ve come across:

64-bit and VT mode

64-bit virtual machines are only supported on CPUs that have VT mode.

Fusion-only feature not handled gracefully by Server

If your .vmx file has the following line, remove it.

serial0.fileType = "thinprint"

VMWare Server does not support this feature, and crashes when you try to import the virtual machine.

Networking

After importing the virtual machine, when you power it on for the first time, VMWare will ask you whether you moved it or copied it. Tell VMWare that you moved it. Otherwise, you will have to manually update the ethernet adapter settings to get networking back up.

Full Post + Comments

My .vimrc

Vim session

I’ve had a few requests for my Vim settings recently. I might as well share it in a blog post. So here’s my .vimrc.

Full Post + Comments

Why is the iPhone a big deal?

Oh hellooo there

I know this. Put an iPhone into my hands, and I want to build software for it. There is just something about this device that compels me. I want to write something for it, even if I end up being the only user of my creation.

I never have this reaction when I interact with Windows Mobile & co. I wouldn’t even bother downloading the SDK unless I’m working for a shop that builds applications for one of these platforms.

So I do download the iPhone SDK and I check it out. And I go wow, I can do all this with minimal fuss? This thing makes me look good! But wait it gets better. They give me an app store that allows me to reach millions of customers. Sign me up!

And ladies and gentlemen, this is why the iPhone is a big deal. There are thousands and thousands of developers out there who are thinking the exact same thing.

Full Post + Comments

Topre Realforce 86U

Topre Realforce 86 Keyboard

I’ve had the Topre Realforce 86U tenkeyless (no numeric keypad) board for several months now. It is my all time favorite when it comes to keyboards. It’s got a superlative key feel and a fantastic build quality. Plus it comes with a red esc key. That has to count for something.

The tactile feedback; the soft, rhythmic thock thock of the keys on the way back up; the sheer poetry of cutting code in Vim while I’m in the zone. That’s the drug I live on. The creative high that I keep chasing. The reason why I program.

Full Post + Comments

New Vim colour scheme – vylight

If you like this colour scheme, check out vydark, the dark background version.

I have recently started playing with Objective-C and Cocoa. One of the first things that I did was to tell Xcode to use MacVim as my default code editor. In the past, I have mostly been using Vim colour schemes with dark backgrounds.

However, I now wanted a colour scheme with a light background. Something that would fit in well within the Xcode environment and OS X in general. It had to be subtle and easy on the eyes. I looked around, and couldn’t find one that I liked. So I made my own. I’m calling it vylight.

Here’s a screenshot showing syntax highlighting for Objective-C. Search strings are highlighted in light yellow. Selected text is in light blue to fit in with aqua. TODOs and FIXMEs are highlighted in light green in comments.

Text highlighting in vylight

This is what omni completion looks like:

Text highlighting in vylight

Syntax highlighting in PHP:

Text highlighting in vylight

And JavaScript:

Text highlighting in vylight

Installing vylight

  1. Download the latest version of vylight.vim from vim.org
  2. Copy the file to your ~/.vim/colors/ directory
  3. In Vim, do :colorscheme vylight

Full Post + Comments

That iPhone thingy

So I got an iPhone 3G last Friday. Initial thoughts:

  1. The screen is absolutely gorgeous.
  2. The Exchange integration works as advertised. I’m now getting my work emails / calendar events pushed to my phone. The challenge now is not to become a slave of my email.
  3. You quickly take the GPS functionality for granted. Got a meeting at a client’s site? Search for the address, tap “get directions” and “from current location”.
  4. SMS listed by conversation. The way it should be.
  5. It doesn’t take very long to get used to the on screen keyboard.
  6. It does not take very long to fill up the iPhone with 8GB of content. Go for the 16GB model.
  7. Polish through and through. This stuff is years ahead of the Symbian/UIQ stack that came with my previous smartphone.
  8. Twitterrific gets my vote for the best app so far in the app store. I just need something like Adium for the phone and I’ll be set.
  9. The remote app gets my vote for the second best application in the app store.
  10. Playing with this device makes me want to build software for it.

Apple make gorgeous hardware, but their main strength is that they understand software, and how to build great systems (the plumbing) and applications (user-facing). They see themselves as a software company that happens to build hardware too. Contrast with HTC who make very good smartphones, but who ultimately rely on Microsoft and the WinMo stack.

The importance of iTunes cannot be underestimated. No one had an answer to it in the PMP market. Now mobile phone manufacturers may find that building a better phone than the iPhone is not enough. Building a better OS than the iPhone OS may not be enough either. On the other side of the equation lies iTunes, which is more than just a syncing app. iTunes is about content distribution (music, movies, TV shows, audio books, applications, and whatever else Apple decides to get into really).

And how about MobileMe? Can you see another phone manufacturer getting into… web 2.0?

So it’s about:

  1. The hardware
  2. The software
  3. The content
  4. The services

No one else is offering a stack like this.

Full Post + Comments

PHP is not a framework

This post started as a comment on Kay’s blog post about Akash Mehta’s post titled “Last we checked, PHP IS a framework”. But my comment veered off-topic. So here we are. Feel free to recurse back and read what they had to say on the subject.

I would not call PHP a framework. I tend to think of it as a language that has a useful set of built in functions that are geared for the web. Some of these functions have poorly chosen names and inconsistently ordered parameters, but that’s another rant for another day.

I think of these functions as a standard library. Frameworks tend to encourage specific patterns. PHP and its built in functions do not have an opinion on patterns. Thus, I make the distinction between a library and a framework. Even PEAR is considered to be a library by most people. So it is a stretch trying to call PHP a framework.

PHP is popular because it has a low barrier to entry. It is easy to get started with, it’s free, it runs on many platforms, and is readily available through most hosting companies. This means that it attracts a lot hobbyists and dabblers. I’ve seen my share of horrible, horrible PHP code. But nothing in the language prevents you from writing good, maintainable code.

Ultimately, the big guys like Yahoo! probably picked not just PHP, but the LAMP stack as a whole. It is a proven, fast, scalable stack. Importantly, it is also one that does not have a major stakeholder like Microsoft (.Net), Adobe (ColdFusion, Flash) or Sun (Java). With the recent talk of Microsoft acquiring Yahoo!, can you imagine the leverage that Microsoft might have had if Yahoo! had built its business on top of Microsoft technology?

When assessing PHP, it is often the sum that is the LAMP stack that wins out. Not the PHP part by itself.

Full Post + Comments