Switching projects in your terminal, quickly!

Jeroen Visser
Jeroen’s Personal blog
2 min readFeb 15, 2015

--

Update: Since a few months I’ve been using fasd, a fast directory switcher, and it has worked better than ever. I’ll still keep my tool out there, but if you want to increase productivity, definitely have a look.

So, a few months ago, I started on a project named project-switcher. It was supposed to be an easy way to switch between project on the command-line without cd’ing to all the directories. Tab completion is fast, but it wasn’t fast enough. I figured you could have something like this:

$ p gfb

And it would then switch to my project, GitFlow Backend. Very easy. I thought it was super-easy to make, but I was wrong. The basics are easy, that’s true, but the problem here is that you have to switch directories. You can’t do `cd ${ folder }` in Ruby, because you’re not doing that for the active shell. You had to be able to execute a command in the current shell, I thought. After working on it for 3 days, I gave up. I thought it wasn’t possible.

But, it seems like it was! After all, the tool is live and working. I resumed working on the tool, about 1 or 2 months after I gave up. I found a way to do it. I would create a shell function, and that would then eval the returned text. I would return echo ‘some text’ if I wanted to echo something out to the console, and if I wanted to eval something, I just print the command and it will be executed.

The week I figured that out, it went really fast. I’ve still got some cool ideas (like autocompletion, fuzzy matching etc.), but I’ve got myself a MVP. You’re free to try it out! Just run the command below and it installs itself. If you ever want to remove it, run the second command.

# Install
$ \curl -sSL http://goo.gl/uHTb1g | bash -s
# Uninstall
$ p --uninstall

--

--