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.


-c context
Use context instead of the program name that salias is given.
-f config
Use the file config instead of the default ~/.salias for configuration.
Instead of executing program, merely print out what would be executed, with the aliased arguments expanded. Note that the output is shell-quoted.
Print out version information and exit.
Print out help information and exit.


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.


context name
Start a new context. When salias used to run a program named name, salias will use this context to determine how to alias arguments.
alias alias_name alias_value...
repeat program_arg...
defaults defaults_name

Transparent Wrapping

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.

Using 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/:

# 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 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 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:

$ salias gpg -kv project-list
gpg -kv 56FFD10A260C4FA3 0x1234ABCD
$ salias -c gpg echo mykey
echo 56FFD10A260C4FA3
$ salias gpg -r project-list --encrypt
gpg -r 56FFD10A260C4FA3 -r -r 0x1234ABCD --encrypt
$ salias ssh-add all frank
ssh-add /home/me/.ssh/id_dsa /home/me/.ssh/identity frank




Frank Tobin


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