Module cnf::alias

source ·
Expand description

Command aliases.

Aliases can be thought of as a way to skip interactions with the application TUI for repeated use of a specific command. In the UI, there is an option to create an alias for any executable command. When selected, cnf writes a shell-script named after the command cnf is supposed to search into a special directory. This script will then perform the same steps as the execute action for the selected entry.

When the application hooks are set up, this special directory is automatically appended to the system $PATH and aliases are immediately available as CLI commands. This is a convenient method to call e.g. podman from inside a toolbx/distrobox container.

§Additional comfort

Once aliases are set up, one can extend their shells completions with the command completions for the aliased commands taken from the environment the command is run in. The following snippet adds shell completions for commands installed on the host to zsh running in a toolbx container:

# add this to your `~/.zshrc`, replacing/extending any previous call to `compinit`!
HOST_COMPLETIONS="/run/host/usr/share/zsh/site-functions"
[[ -d "$HOST_COMPLETIONS" ]] && fpath+="$HOST_COMPLETIONS"
compinit -u

This works because, by default, toolbx containers map the hosts entire filesystem beneath /run/host. The zsh completion files for system utilities are found in /usr/share/zsh/site-functions, which is added to the zsh fpath in case the directory exists (which is only the case inside a toolbx container, not on the host). Then we call compinit to initialize the zsh command completions, passing the -u option so it ignores permission/ownership issues on the host completions folder (this bit seems unavoidable).

Once this is done, command aliases for system utilities installed on the host should have full tab completion (e.g. container names for podman, subcommands/network names for nmcli and more)!