Author: | Jeet Sukumaran |
---|---|
Contact: | jeetsukumaran@frogweb.org |
Date: | 2007-09-12 |
Version: | 1.0a |
This program is a little utility that has made my life in bash so much easier that I just had to share it. I do not pretend that it is perfect (I can think of dozens of improvements), nor comprehensive (I wish I could use it to manage paths), nor even original (I came across the "go" command on the web, and its aliasing feature was the inspiration behind this program). However, it does its job well enough for me, and as I am releasing it under the GNU GPL 2 License, you are free to do what you want to get it to work for you as well.
So, what exactly does it do? In a nutshell, it manages a list of directory aliases: short strings that serve as stand-ins for long, deep path specifications. With a simple command ("jd"), you can jump to anyone one of these aliased paths.
Any POSIX-based shell environment with Python 2.4 or greater.
Important
I've assumed that your shell uses a file called ".bashrc" in your home directory (i.e., "~/.bashrc") as its configuration file. Obviously, this far from universally true, and, it cannot even be said to be generally true. There are dozens of other conventions. I've been meaning to modify the code to behave smarter, and search for an appropriate configuration file, but I have not. I might in the next release. The workaround, however, is fairly simply, and is detailed below.
Installation is very straightforward. The script has the ability to "bootstrap" itself into installation. Simply execute the script with the "--install" argument:
python jdalias.py --install
You do not need root permissions or anything like that. The scripts basically creates a directory called ".jdalias" in your home directory, writes a copy itself to it, creates a new shell script file there, and then modifies your "~/.bashrc" file to source the shell script.
As noted above, if your shell environment does not rely on "~/.bashrc", after running the installation option, you will have to modify the appropriate file by sourcing the shell script using the following line:
. ~/.jdalias/jd.sh
For example, if your shell environment uses "~/.cshrc" as its resource/configuration file, the following command executed at the shell prompt should do the trick:
echo ". ~/.jdalias/jd.sh" >> ~/.cshrc
To begin using the program, simply go to a directory that you want to alias ("bookmark", "tag", etc."), and type:
jd -a <ALIAS>
Or:
jd --add <ALIAS>
Where "ALIAS" is a shortcut that is short enough to be quick and easy to type, yet meaningful enough so that you can remember it. For example:
cd ~/Development/Python/Projects/Utilities/MyProject/trunk jd -a myproj
From now on, no matter where you are in the filesystem, you can always get to "~/Development/Python/Projects/Utilities/MyProject/trunk" by typing:
jd myproj
To see a list of shortcuts that you have defined, you would type:
jd -l
Or:
jd --list
For that matter, if you type in "jd" without arguments, you will also be shown a list of defined aliases.
I've also incorporated bash autocompletion, and if you type "jd", space, and then <TAB> and the first couple of characters of an alias, you should be presented with a list of possible completions.
To remove a defined alias, use the "-r" option:
jd -r myproj
You do not need to specify the full alias to refer to it: you can use just enough characters to specify it ambigiously, or use its numerical index.
For example, assuming the following is your alias list:
$ jd -l 1: admin /home/jeet/Administration 2: bin /home/jeet/bin 3: proj11 /home/jeet/Documents/Projects/Proj11 4: proj22 /home/jeet/Documents/Projects/Proj22 5: proj33 /home/jeet/Documents/Projects/Proj33 6: refs /home/jeet/A/Very/Long/Path/To/Some/References
Then "jd a" will take you directly to "/home/jeet/Administration", "jd b" will take you to "/home/jeet/bin", and "jd r" will take you to "/home/jeet/A/VeryLong/Path/To/Some/References".
However, since "jd p" cannot resolve an alias unambiguously, you would need to type in the alias at least to "proj1", "proj2", or "proj3" for the alias manager to know which alias you are referring to.
You can also use the numerical index of an alias definition as a stand in for the alias. For example, given the alias definitions above, "jd 1" will take you to "/home/jeet/Administration", "jd 3" will take you to "/home/jeet/Documents/Projects/Proj11", and "jd 6" will take you to "/home/jeet/A/Very/Long/Path/To/Some/References"
The program will not complain if you assign two or more aliases to the same path, but if you try an redefine an existing alias, you will be prompted for confirmation.
The aliases are maintained in a file, "jdalias.defs" in the "~/.jdalias" directory. Deleting this file will clear all the aliases. You can also modify the file with a text editor if you want more control over the alias definitions or the ways that you can edit them.
Other than that, there is not much more to it. "jd --help" gives you a list of all the options that are available to you.
There is no automated uninstall procedure, but installation is pretty straightforward. You have to do two things:
Edit your shell resource file ("~/.bashrc", or whichever file your shell uses) to remove the line(s) in which the jdalias shell script is sourced:
# source jdalias wrapper function . /home/jeet/.jdalias/jd.shDelete the jdalias directory:
rm -rf ~/.jdalias/
Copyright 2007 Jeet Sukumaran (jeetsukumaran@frogweb.org)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.