cd to a directory of a file

| 3 Comments

In zsh, define the following function:

cd-()
{
    local dir
    cd `dirname $1`
}

Then this:

cd- /usr/ports/www/linux-opera/Makefile

changes directory to /usr/ports/www/linux-opera/.

Trivial pleasure, but pleasure nevertheless.

3 Comments

Here is a more zsh way to do it :) no more dirname
cd-()
{
cd ${1:h}
}

You also don't need the "local dir" line.

Bapt: yeah, thanks, your code is definitely better.

Nice!

Joink directly into my .zshrc :)

Leave a comment

About this Entry

This page contains a single entry by tobez published on April 4, 2007 9:31 PM.

Google disk failures paper was the previous entry in this blog.

Switching between X11 screens and workplaces with keyboard is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.