We're hiring!

We're actively seeking designers and developers for all three of our locations.

Working Faster with Working Directory

I always have a shell open. Most of my daily project navigation and file-system work is done in Bash. If I can do something with a GUI or a terminal, I’ll prefer the terminal. I’m a polyglot programmer who often uses Windows, Linux, and Mac OS X all in the same day. There’s a tool I need whenever I work on the command-line: Working Directory.

Here’s a scenario:

Your project uses Java and Maven. That means the first useful bits of your code are buried somewhere like this:


/Users/capt.picard/work/FooFoo/src/main/java/org/foo

So you start out a new shell in your home directory and navigate all the way down there:

1
2
3
4
/Users/capt.picard$ cd work
/Users/capt.picard/work$ cd FooFoo
/Users/capt.picard/work/FooFoo$ cd src/main/java/org/foo
/Users/capt.picard/work/FooFoo/src/main/java/org/foo$

Whew! Maybe not a big deal once, but I hope you don’t have to do this every day! Fortunately you have command-line completion, cutting down on all that typing:

1
2
/Users/capt.picard$ cd wo[TAB]/Foo[TAB]/s[TAB]/m[TAB]/j[TAB][TAB][TAB]
/Users/capt.picard/work/FooFoo/src/main/java/org/foo$

Wait, what? That’s still a lot of typing! This is much quicker for users of Working Directory:

1
2
/Users/capt.picard$ wd
/Users/capt.picard/work/FooFoo/src/main/java/org/foo$

That’s it! Let’s see how that magic works.

Whenever you start a new project or workspace, just tell Working Directory (or just “wd”) that you want to make a new scheme:


/Users/capt.picard$ wdscheme foofoo

This creates a set of 10 slots associated with that scheme and copies in the contents of your previous scheme. (If you don’t need a clone of the previous scheme, you can clear those out with wdc.) Now you simply navigate to your project root, or wherever you most commonly need to start when you work on that project, using regular cd and all the tab-completions you can tolerate. Once there, you can store that directory in the default slot like this:


/Users/capt.picard/work/FooFoo/src/main/java/org/foo$ wds

If you then look at the list of slot assignments with wdl, you’ll see that you’ve stored the current directory in the 0th slot:

1
2
3
4
5
6
7
8
9
10
11
/Users/capt.picard$ wdl
0 /Users/capt.picard/work/FooFoo/src/main/java/org/foo
1
2
3
4
5
6
7
8
9

The first slot is special—you can access it without specifying a number at all. Just type wd to navigate to that slot and wds to set it to the current directory. The remaining slots require their number to retrieve or store. If you want to store the directory that holds your project tests in slot 3:

1
2
3
4
5
6
7
8
9
10
11
12
13
/Users/capt.picard$ cd work/FooFoo/src/test/java
/Users/capt.picard/work/FooFoo/src/test/java$ wds3
/Users/capt.picard/work/FooFoo/src/test/java$ wdl
0 /Users/capt.picard/work/FooFoo/src/main/java/org/foo
1
2
3 /Users/capt.picard/work/FooFoo/src/test/java
4
5
6
7
8
9

Now you can quickly navigate between source and test on the command-line:

1
2
3
4
/Users/capt.picard$ wd
/Users/capt.picard/work/FooFoo/src/main/java/org/foo$ wd3
/Users/capt.picard/work/FooFoo/src/test/java$ wd
/Users/capt.picard/work/FooFoo/src/main/java/org/foo$

You can have as many schemes as you want, but each scheme only stores 10 directories. This allows for maximum accessibility on the command-line with single-word aliases for going to or storing into each slot.

Working Directory has many other features that you may start to use over time:

  • wdenv stores the current scheme into similarily-named environment variables for easy use on the command-line for any purpose, like cp.
  • Storing directories in slots doesn’t require that you be in the directory. Just give a directory as a parameter to wds[0-9] and it will store it instead of the current directory.
  • wd is cross-platform, written in Bash and Perl. I’ve used it heavily over the years on Windows+cygwin, Linux, OS X, and Solaris.
  • wd provides a bash-completion function for its schemes. wdscheme [TAB][TAB] will list of all of your existing schemes.
  • Since wd stores schemes and slots on disk, all of your terminals will share the same scheme, so there’s no need to set the scheme every session. Storing a directory from one terminal makes it available in any other terminal.
  • You can also temporarily override the working scheme in a particular shell by just setting the value of the environment variable WDSCHEME. If this variable is set, it’s used instead of the current scheme on disk.

Working Directory has been available for some years and gets constant daily use by its small community. Most people who’ve started using it never stop! Lately you can fetch the source from github or download the latest stable release directly from the project’s Downloads area.

Karlin Fox (44 Posts)

This entry was posted in Developer Tools. Bookmark the permalink. Both comments and trackbacks are currently closed.