Utilities for Managing Bash Aliases
IntroductionThe bash shell has three features that facilitate speedy command entry (and thus help prevent repetitive stress syndrome and carpal tunnel medical problems):
The alias feature makes it easy to enter frequently used lengthy commands. For example:
% alias gr="grep '^ABC' data*.txt | cut -d^A -f2,4,6,7 | less" % gr % gr
To make an alias definition permanent (for the next time you log in)
you need to put it in a file and source that file.
One way of doing this is to put all alias definitions in
This is all well and good but ... the time and forethought required to create these definitions is often a significant barrier that is difficult to overcome. Even though the time it would take to create an alias would save much time in the long run (and much stress on hands and wrists and arms) the task at hand always seems to take priority. And so one rarely does.
This collection of bash alias utilities helps overcome the clerical burden of creating aliases.
The installation of these utilities is detailed below but first let's take a look at what the utilities provide.
There are these commands:
With proper use of local aliases, you can have 'e' mean to edit one thing
here and another thing there. There is less of a need to
invent unique alias names. The name
'ga' and 'al' are sometimes used just to see what aliases you have defined. The global and local alias files are often easier to look at than the output of the bash command 'alias'.
The editor used for 'ga' and 'al' is by default vi. If you have defined $FCEDIT or $EDITOR it will be used instead.
% alc 1 vi pookie.pl 2 grep '^ABC' data*.txt | cut -d^A -f2,4,6,7 | less 3 cd ~/src/lib 4 ls -l 5 vi bigg.pl 6 vi big.pl 7 perl big.pl 8 ls -lt *.pl 9 perldoc -f split Which command and what alias? 2 gr %The new alias 'gr' is put in the local alias file,
If you want to see more than the last 9 commands you can define an environment variable named NALIASES.
% export NALIASES=20 % alc 1 vi little.pl 2 awacs ls -stream -f strict | less 3 cd ~/src/lib 4 ls -l ... 19 vi the_file.txt 20 vi vif.pl Which command and what alias? 19 talc except that the newly created alias is put in the global alias file
% cd /net/data/properties/shopping/source/daily % acd alias for /net/data/properties/shopping/source/daily? nds % cd /home/joe/data/daily/shopping % acd alias for /home/joe/data/daily/shopping? jds % nds /net/data/properties/shopping/source/daily % cp out.txt $jdsThe last two commands move to
AND, most importantly, on moving to the new directory the local alias file is sourced for you. To see the utility of this feature let's say that you have two current projects that live in two different directories. In each, you edit and run a Perl script. With proper use of acd and alc, command entry becomes easy to remember, simple, and quick.
% cd /home/charlie/dev/properties/mail/sent % acd alias for /home/charlie/dev/properties/mail/sent? sn % vi tally.pl % perl tally.pl % alc 1 vi tally.pl 2 perl tally.pl Which command and what alias? 1 e 2 x % cd /home/y/share/htdocs/gui % acd alias for /home/y/share/htdocs/gui? gu % vi show.pl % perl show.pl % alc 1 vi show.pl 2 perl show.pl Which command and what alias? 1 e 2 xIf we perform the above commands once we can then proceed very smoothly:
% sn ( move to the mail/sent directory ) % e ( edit tally.pl ) % x ( run tally.pl ) % e % x % gu ( move to the htdocs/gui directory ) % e ( edit show.pl ) % x ( run show.pl ) % e % xacd. Only the last component of the directory is shown. Give the -l option if you want the full directory name.
If you liked these time (and hand and wrist) saving tips also see: Perl and Vi - A Poor Man's IDE