Quick Directory Aliases
Enables quick directory aliases and navigation. Allows for easy and consistent navigation between disparate directories.
Table of Contents
- Download the script
- Source the script into your current shell (add this to your shell startup script to always have the command available)
Quick setup commands
Note: Before running the following, change
RC_FILEto 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.shscript and change the function name
d()to a name of your choosing.
Add an alias
% cd /any/really/long/or/short/directory/path/thats/hardoreasy/to/remember % d + shortAliasName
Note: changes take effect immediately across terminals/shells.
Navigate to an alias
% d shortAliasName % pwd /any/really/long/or/short/directory/path/thats/hardoreasy/to/remember
Remove an alias
% d - shortAliasName
See all aliases
% 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
Installation is automatic and works like any other bash/zsh tab based autocomplete.
Using with ssh to have your list of aliases available anywhere (not yet implemented)
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
~/.dmapfile 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.