Enables quick directory aliases and navigation. Allows for easy and consistent navigation between disparate directories.
Installation
Usage
Autocomplete
Supported Environments
Implementation Details
License
- Download the script
- Source the script into your current shell (add this to your shell startup script to always have the command available)
- Done
Note: Before running the following, change
RC_FILE
to match your preferred shell's rc file, or any other file that you source when a new shell/terminal is created.
RC_FILE=~/.bashrc
SCRIPT_DIRECTORY=~/scripts
mkdir -p $SCRIPT_DIRECTORY
wget -O $SCRIPT_DIRECTORY/quick-directory-aliases.sh https://raw.githubusercontent.com/mcwoodle/shell-directory-management/master/quick-directory-aliases.sh
printf "\n. $SCRIPT_DIRECTORY/quick-directory-aliases.sh\n" >> $RC_FILE
. $RC_FILE
The default name for the command is "d". Edit the
quick-directory-aliases.sh
script and change the function named()
to a name of your choosing.
% cd /any/really/long/or/short/directory/path/thats/hardoreasy/to/remember
% d + shortAliasName
Note: changes take effect immediately across terminals/shells.
% d shortAliasName
% pwd
/any/really/long/or/short/directory/path/thats/hardoreasy/to/remember
% d - shortAliasName
% d
workspace = /home/mcwoodle/workspaces/someWorkspaceDirectory
bin = /usr/bin
nhl = /home/mcwoodle/go/leafs/go
Autocomplete is currently only supported using bash and zsh (or any script supporting complete\compgen
or compctl
built-ins).
Installation is automatic and works like any other bash/zsh tab based autocomplete.
If you're like me and work with a lot of remote servers, you could use something along the lines of:
ssh -t <user>@<hostname> "someScriptOrCommands_ToLoadMapFileAndSourceScript; zsh"
to push the ~/.dmap file along with the above script in order to get all of your aliases available remotely no matter which host you sign in to.
I have yet to implement this solution yet, but it's on my todo list. If you get to it first, please let me know your approach. Thanks!
This script uses standard sh and will work with any POSIX compliant shell. It's been tested with sh, bash, ksh, zsh, dash and been used on macOS, RHEL5, Ubuntu, and Bash on Ubuntu on Windows.
C shell, tcsh/csh, are not POSIX compliant and therefore not supported.
ksh on Bash On Ubuntu On Windows, along with being a mouthful, does not work due to a "cannot create pipe [Operation not permitted]" error when piping output to sed.
Autocomplete only works on bash and zsh.
- The script is sourced into your current working shell, allowing it to issue change directory commands within your shell.
- A function will be defined named 'd' in the current shell's context. If there is an alias with this name it will be removed.
- It creates and uses a
~/.dmap
file to store a map of aliases to directories. - This map file can easily be edited manually (e.g. bulk renaming).
Licensed under the Apache License, Version 2.0.