aliaseris a self-editing alias management tool.
This tool was created to manage persistent aliases when using bash or zsh interactively.
aliaser consists of a single bash function that stores its own aliases. Each alias crated with aliaser is appended to the bottom of the aliaser.sh script itself. When you source aliaser.sh you add the aliaser function, and all of the aliases created with this function, to your environment. Please see aliaser.sh to see how this works.
Important
While aliaser is currently a sourceable function, the next major version of the tool will exist as a standalone bash script. This will ensure aliaser.sh is isolated from the base shell environment.
Important
aliaser is written in bash, tested interactively in zsh on MacOS and passes most shellcheck tests. This script has not been tested on any Linux-based systems (Linux compatibility coming soon).
The source code for aliaser can be found at github.com/unforswearing/aliaser
Clone this repo and source aliaser/aliaser.sh to get started.
$ git clone https://github.com/unforswearing/aliaser.git .
$ source aliaser.sh
$ aliaser helpFor persistent use you may source aliaser from your .bashrc, .zshrc, or other shell configuration files. The aliaser script must know its own location, so be sure to set up the ALIASER_SOURCE environment variable so that it points to aliaser.sh.
# in your $dotfiles:
export ALIASER_SOURCE="path/to/aliaser/aliaser.sh"
source "$ALIASER_SOURCE"fzfgnu-sedasgsedon MacOS
Typing aliaser help prints help documentation, including the following list of options:
Options:
help display this help message
list list aliases saved in alias file
dir create an alias with 'name' that will cd to 'path'
lastcmd create an alias from the previous command in your history
edit edit alias file in ${EDITOR}
search search aliases, select and print matches
open open the 'aliaser.sh' script in ${EDITOR}
clearall remove all aliases from this alias fileAliases can be added to the aliaser.sh script using the folling commands:
aliaser dir <name> <path>
aliaser lastcmd <name>
Running aliaser without an option flag will allow you to save aliases to this script in a slightly more traditional manner:
aliaser <name='command'>
Double quote the entire argument to ensure your aliases are not mangled by the script.
aliaser "cd_home_ls='cd $HOME && ls'"Use aliaser list to print a list of the aliases currently stored in the script.
The aliaser search <query> command will allow you to search your aliases for items matchin query. aliaser will print the result of the search, or a warning if no match was found. If there is more than one search result, aliaser will use fzf to let you select between the available matches.
The aliaser edit command can be used to add new aliases manually, or remove aliases from your list. This is especially useful if you would like to enter multiple aliases at once.
aliaser does not have a builtin command to remove individual aliases from the list. Please use aliaser edit to modify individual entries. You may use aliaser clearall to remove all aliases from the list.
If you find that an alias has been accidentally mangled, use the aliaser edit command to modify any alias stored in the script. You may also use aliaser open to modify the aliaser.sh script directly, debug your aliases, or improve the code.
aliaser has some example aliases stored at the bottom of the script to show how aliaser stores aliases. Run aliaser clearall to remove these examples before adding your own aliases.
$ aliaser dir "project_dir" "$HOME/projects"
Added: alias 'project_dir':
> cd "/Users/unforswearing/projects"$ sleep 2 && echo awake
awake
$ aliaser lastcmd "wakeup"
Added: alias 'wakeup':
> "sleep 2 && echo awake"Work is currently uderway to update aliaser. See TODO.md