Global and local aliases
The shell allows declaring not only standard aliases, which are available
everywhere, but also aliases which available only in the selected directories.
For example, you can declare alias build
which in one directory will be
executing make -j5
and in another nim release
. Aliases can be declared for
just one directory or for each subdirectory of the selected directory, too. At
this moment, available options for aliases are:
- ID: The ID of the alias, used mostly for deleting the selected alias
- Name: The name of the alias. The text which have to be entered to execute the alias. It doesn't need to be unique, but if two aliases in the same directory have the same name, then the first one will be executed. The name can contain only letters, numbers, and underscores.
- Path: The main directory in which the alias works. Must be an existing directory.
- Recursive: If set to 1, the alias is available for all subdirectories of the main directory. If set to 0, is available only in the selected directory.
- Commands: The list of commands which will be executed as alias. The alias can execute a few commands, but then, each entry on the list have to be separated with new line.
- Description: The alias description. Showed on the aliases list.
- Output: Where to redirect the output of the commands executed by the alias.
By default, or if this option set to
stdout
, the output not redirected at all. If set tostderr
, then the standard output redirected to the standard error. When set to any other value, it is the path (relative or absolute) to the file to which the output will be saved. If the file exists, the output will be added to its content. IMPORTANT: only default setting allows interacting with the commands executed by the alias. Any other setting allows only read without any ability to pass any input to the executed commands.
For example, the definition of the alias can look that:
ID: 1
Name: mc
Path: /
Recursive: 1
Commands: mc --nosubshell
Description: Run MC without subshell
Output: stdout
The alias will be executed when the user enters mc
in the shell. The alias is
the global alias, it is available for the main directory /
and all
subdirectories. It executes command mc --nosubshell
. The output of the alias
will be as default, nothing is redirected.
The definition of the local alias can look that:
ID: 2
Name: listdocs
Path: /home/user
Recursive: 0
Commands: cd docs && ls -lh
Description: Enter docs directory and list all files
Output: result.txt
The alias will be executed when the user enters listdocs
in the shell in the
home directory. It doesn't work in any of its subdirectory. It enters docs
directory and then runs the command ls -lh
. If the next command should be
executed only when the previous command was successful, use &&
to merge them.
If the next command should be executed only when the previous failed, use ||
to merge them. The output of the alias will be redirected to the file
result.txt
which will be located in the same directory where the alias was
executed.
You can also pass arguments to the commands of the alias. The substitutes for
arguments are start with $
and have numbers from 1 to 9. Example: $1
, $5
.
The definition of alias which uses arguments can look that:
ID: 3
Name: fossopen
Path: /home/user/Projects
Recursive: 0
Commands: fossil open fossil/$1.fossil --workdir $1
Description: Open fossil repo. Required parameter is the name of fossil repo.
Output: stderr
The alias will be executed when the user enters fossopen [reponame]
in the
shell. When the user enters only fossopen
the shell will report a problem. The
alias is the local alias, which means it doesn't work in subdirectories. It
runs command fossil open fossil/[reponame].fossil --workdir [reponame]
. For
example, entering the shell's command: fossopen myrepo
will execute command:
fossil open fossil/myrepo.fossil --workdir myrepo
. The output of the command
will be redirected to the standard error.
There is also special argument $0
which mean all remaining arguments entered
by the user. The definition of alias which uses that argument can look that:
ID: 4
Name: foss
Path: /
Recursive: 1
Commands: fossil $0
Description: Alias for command fossil.
Output: stdout
The alias will be executed when the user enters foss
or foss [arguments]
in
the shell. For example, entering the shell's command: foss help
will execute
command: fossil help
. The output of the alias will not be redirected.
To start defining a new alias, the user can use command alias add
. To edit an existing alias, the user can use command alias edit [ID]
where ID is the ID of the alias to edit. The more information about the commands related to the aliases is available in shell with command alias
. It is also possible to manipulate aliases with the SQLite shell.