The service provided by Consileon was professional and comprehensive with a very good understanding of our needs and constrains.

Wolfgang Hafenmayer, Managing partner, LGT Venture Philanthropy

Technical quality of staff offered, capability of performing various project roles, as well as motivation and dedication to the project (... [...]

dr Walter Benzing, Head of development B2O, net mobile AG

Technical quality of staff offered, capability of performing roles of developers, lead developers, trainers, team leaders, architects as wel [...]

Karl Lohmann, Itellium Systems & Services GmbH

Firma Consileon Polska jest niezawodnym i godnym zaufania partnerem w biznesie, realizującym usługi z należytą starannością (...)

Waldemar Ściesiek, Dyrektor zarządzający IT, Polski Bank

The team was always highly motivated and professional in every aspect to perform on critical needs of our startup environment.

Denis Benic, Founder of Ink Labs

Fast terminal file system navigation

Category: Other Tags: ,

When it comes to file system navigation in terminal, default solutions often are too clumsy. In bash autocompletion is annoying because of case-sensitivity. On the other hand zsh can autocomplete case insensitively and with fuzzy string searching but it matches only names in the working directory.

Thankfully there is a tool for the most popular shells that greatly improves navigation speed: autojump. Bascially it remembers (in own database) every directory you’ve visited and allows you to easily jump to them via autojump or more convenient j command.

Installation

Autojump can be easily installed via following package tools: yum, apt-get, brew, ports. For this post I’m using Mac OS X with zsh and brew.

brew install autojump

After installation completes one last thing must be done: autojump.sh must be added to the terminal rc file (.zshrc in my case, lines suggested by the brew):

[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh

Usage

The key to successful autojumping is to get rid of habit of cd usage. Instead of typing few cd .. and then cd <tab> just use j alias.

This post is based on the following example: we have a projects directory which contains exact client names, which further contain exact project names.

projects
├── Bathing Company Inc
│   └── bath-shop
├── Cinnamon Cafe
│   └── gadget's-shop
└── The Washers
    └── shop

First things first: create projects with Bathing Company Inc, then visit it and navigate somewhere else (home should be fine). To get back to that nested, annoying space-named directory simply enter j bath.

Matching multiple directories

When navigating through the file system for a while you will visit directories with the same name or same name parts. This is easily handled by the autojump.

For this example every directory in the projects tree must be visited.

Let’s try to enter Cinnamon Cafe’s shop (j shop<tab>). It expands to something like this:

j shop__

Hit tab again and you will get prompt like this:

shop__1__/Users/username/projects/Bathing\ Company\ Inc/bath-shop
shop__2__/Users/username/projects/Cinnamon\ Cafe/gadget\'s-shop
shop__3__/Users/username/projects/The\ Washers/shop

At the first glance it’s ugly and messy. Nothing further from the truth. Just look at ending of the prompt, then look at the number. It is indexed for the convenience! Instead of typing Cinnamon Cafe’s in our case we just add 2 to our j shop__ and hit enter.

j shop__2

Then we navigate to the Bathing Company’s shop.

j shop__1

Fast and simple. But there is more goodness in the autojump. It reorders indexes based on the usage. So after we’ve jumped few more times to the Cinnamon’s Cafe, we will get the folowing prompt:

shop__1__/Users/username/projects/Cinnamon\ Cafe/gadget\'s-shop
shop__2__/Users/username/projects/Bathing\ Company\ Inc/bath-shop
shop__3__/Users/username/projects/The\ Washers/shop

Notice that 1 is now Cinnamon Cafe and 2 is Bathing Company.

Deleting directories

Removing directories in the file system is also supported by the autojump. Deleting whole The Washers directory and trying to jump to the shop will give us prompt without deleted directory:

shop__1__/Users/username/projects/Cinnamon\ Cafe/gadget\'s-shop
shop__2__/Users/username/projects/Bathing\ Company\ Inc/bath-shop

Known bugs

As stated on the project’s page:

  • autojump does not support directories that begin with -.
  • For bash users, autojump keeps track of directories by modifying $PROMPT_COMMAND. Do not overwrite $PROMPT_COMMAND

Tomasz Wójcik

Software developer, IT consultant.

A software programmer, master of Java who is not afraid to explore the Ruby on Rails. In the past he developed games in C, Objective-C and ActionScript 3 in these days he loves to do that after hours. Great fan of Git.


Tags: ,

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Trwa ładowanie