Linux shell navigation to aliased directories with autocomplete

A Linux shell script for registering directory aliases and navigating to them with tab completion.

I use the terminal a lot and in my day to day work I tend to navigate to the same bunch of directories.

There are some awesome tools out there (like autojump or z) but sometimes, especially when the directories are similarly named, there is a need to be explicit to navigate to the proper one.

I decided to write a script to overcome this issue and to avoid having to edit my .bash* files to manage aliases each time I wanted to add or remove a directory.

goto

goto is a shell utility to quickly navigate to aliased directories with autocomplete (tab completion).

goto at GitHub

goto gif

User registers directory aliases, for example:

goto --register dev /home/iridakos/development

and then cds to that directory with:

goto dev

Find below documentation on the script but make sure you check the script’s documentation page for updates.

Sorry for the name, I know it brings back memories but it’s not what it seems :)

Installation

To install goto all you have to do is clone the repository locally:

git clone https://github.com/iridakos/goto.git

navigate to it

cd goto

and execute:

sudo ./install

You need to restart your shell after installation.

Usage

Change to an aliased directory

To change to an aliased directory, type:

goto <alias>

Example

goto dev

Register an alias

To register a directory alias, type:

goto -r <alias> <directory>

or

goto --register <alias> <directory>

Example

goto -r blog /mnt/external/projects/html/blog

or

goto --register blog /mnt/external/projects/html/blog

Notes

  • goto expands the directories hence you can easily alias your current directory with:
    goto -r last_release .
    

    and it will automatically be aliased to the whole path.

  • Pressing the tab key after the alias name, you have the default directory suggestions by the shell.

Unregister an alias

To unregister an alias, use:

goto -u <alias>

or

goto --unregister <alias>

Example

goto -u last_release

or

goto --unregister last_release

Notes

Pressing the tab key after the command (-u or --unregister), the completion script will prompt you with the list of registered aliases for your convenience.

List aliases

To get the list of your currently registered aliases, use:

goto -l

or

goto --list

Expand an alias

To expand an alias to its value, use:

goto -x <alias>

or

goto --expand <alias>

Example

goto -x last_release

or

goto --expand last_release

Cleanup

To cleanup the aliases from directories that are no longer accessible in your filesystem, use:

goto -c

or

goto --cleanup

Help

To view the tool’s help information, use:

goto -h

or

goto --help

Version

To view the tool’s version, use:

goto -v

or

goto --version

Extras

Push before changing directories

To first push the current directory onto the directory stack before changing directories, type:

goto -p <alias>

or

goto --push <alias>

Revert to a pushed directory

To return to a pushed directory, type:

goto -o

or

goto --pop
Notes

This command is equivalent to popd, but within the goto command.

Behind the scenes

Upon installation, a line is appended to your .bashrc file which sources the script, registering a goto function responsible for changing the directory based on the defined aliases of the database.

The script creates a directory alias database file under ~/.goto. Every register or unregister action modifies this file.

The script also uses the Bash programmable completion feature to define tab completions resolved via extraction of the aliases defined in the goto database file.

That’s all! Cat photo.

I'll be back

Code and comments
You can find the code of goto at https://github.com/iridakos/goto.
For feedback, comments, typos etc. please open an issue in the repository.
Thanks for visiting!

Share this page