Published on Apr 10, 2019
in category programming
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
is a shell utility to quickly navigate to aliased directories with autocomplete (tab completion).
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 :)
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.
To change to an aliased directory, type:
goto <alias>
goto dev
To register a directory alias, type:
goto -r <alias> <directory>
or
goto --register <alias> <directory>
goto -r blog /mnt/external/projects/html/blog
or
goto --register blog /mnt/external/projects/html/blog
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.
tab
key after the alias name, you have the default directory suggestions by the shell.To unregister an alias, use:
goto -u <alias>
or
goto --unregister <alias>
goto -u last_release
or
goto --unregister last_release
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.
To get the list of your currently registered aliases, use:
goto -l
or
goto --list
To expand an alias to its value, use:
goto -x <alias>
or
goto --expand <alias>
goto -x last_release
or
goto --expand last_release
To cleanup the aliases from directories that are no longer accessible in your filesystem, use:
goto -c
or
goto --cleanup
To view the tool’s help information, use:
goto -h
or
goto --help
To view the tool’s version, use:
goto -v
or
goto --version
To first push the current directory onto the directory stack before changing directories, type:
goto -p <alias>
or
goto --push <alias>
To return to a pushed directory, type:
goto -o
or
goto --pop
This command is equivalent to popd
, but within the goto
command.
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.