salias — alias the arguments of another command
salias [-h] [-v] [-f config] [-c context] program [program_arg...]
The purpose of salias is to provide an aliasing system for programs where arguments may wish to be aliased. This is more useful than just a shell environment variable as an argument, since it can 'repeat' options, such as GnuPG's --recipient option as needed. Also, unlike shell environment variables, it can be used transparently inside of other programs, strengthening it's drop-in capabilities.
salias was initially designed for wrapping around GnuPG, providing aliases for keys. However, the design easily extends to being useful for all types of programs.
Simply call salias before the the program it is wrapping, similar to how you do for time. For example: salias gpg -r mykey --encrypt
salias determines a context in which to to alias arguments based the program upon ~/.salias. See the section Configuration for details.
Another option is to have a wrapper script act as a fully transparent drop-in wrapper. See the section Transparent Wrapping for details.
By default, salias reads ~/.salias for its configuration. The configuration contains sections of 'context'. The definition of a context begins with the directive context followed by a name for that context. All subsequent lines are then used to configure that context until either another context directive is encountered.
Lines are divided into arguments as a shell would process them. This implies that lines of all whitespace and those that begin with # are ignored.
Sure, it's nice to be able to alias arguments when using the shell and prefixing the command salias, but what about other programs that you might want to use these aliases transparently? You don't want to modify them to have to call salias, or have any knowledge of it whatsoever. What you want is a completely transparent drop-in.
There are two ways to go about this: you can simply alias, say, gpg to salias gpg, or, to help other programs which would call gpg and aren't affected by your shell's aliases, you can create a wrapper script.
Fortunately, you can insert salias transparently by using a wrapper script around the calls to the real program you are aliasing for. Take for instance, gpg. By having the file named /usr/local/bin/gpg actually be a wrapper script that calls /usr/local/bin.real/gpg, we can use salias transparently.
Here's an example of a reusable wrapper script that you could link every executable you want salias to handle argument-aliasing for on the system to, after moving the 'real' executables into /usr/local/bin.real/:
#!/bin/sh # salias-wrapper base=`basename $0` exec salias -c "$base" "/usr/bin.real/$base" "$@"
As an example, you could move your 'real' gpg to /usr/local/bin.real/gpg, link /usr/local/bin/gpg to this wrapper script (e.g., ln -s salias-wrapper gpg), which would in turn call the 'real' gpg properly, which the aliased arguments.
Consider the following example configuration file:
context gpg alias frank 4F863BBBA8166F0A340F600356FFD10A260C4FA3 alias mykey 0x1234ABCD alias project-list frank bob@example.com mykey repeat -r --recipient context ssh-add alias all dsa rsa alias rsa /home/me/.ssh/identity alias dsa /home/me/.ssh/id_dsa
Using the defaults directive, we can shorten this and remove the repeat directive:
context gpg defaults gnupg alias frank 56FFD10A260C4FA3 alias mykey 0x1234ABCD alias project-list frank bob@example.com mykey context ssh-add alias all dsa rsa alias rsa /home/me/.ssh/identity alias dsa /home/me/.ssh/id_dsa
Using this configuration, this is the outcome of using salias with some program argument lists:
gpg -kv 56FFD10A260C4FA3 bob@example.com 0x1234ABCD
echo 56FFD10A260C4FA3
gpg -r 56FFD10A260C4FA3 -r bob@example.com -r 0x1234ABCD --encrypt
ssh-add /home/me/.ssh/id_dsa /home/me/.ssh/identity frank
Copyright (C) 2003 Frank Tobin.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/copyleft/lesser.html