Created
February 10, 2021 19:41
-
-
Save Khazbs/923dea22873cee84a6a0ba25a2d7de36 to your computer and use it in GitHub Desktop.
Having this in your ~/.bashrc will allow you to write persistent alias into ~/.bash_aliases with the aka command (and use them without sourcing ~/.bashrc)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Alias definitions. | |
# You may want to put all your additions into a separate file like | |
# ~/.bash_aliases, instead of adding them here directly. | |
# See /usr/share/doc/bash-doc/examples in the bash-doc package. | |
if [ -f ~/.bash_aliases ]; then | |
. ~/.bash_aliases | |
fi | |
# Write new alias to ~/.bash_aliases | |
aka() | |
{ | |
local alias_regex='[A-Za-z_0-9]*' | |
if | |
[[ $# = 1 && $1 =~ ($alias_regex)=(.*) ]] | |
then | |
printf "%s\n" "alias ${BASH_REMATCH[1]}=\"${BASH_REMATCH[2]}\"" >> ~/.bash_aliases | |
. ~/.bash_aliases | |
else | |
echo "Usage: aka ALIAS_NAME=ALIAS_COMMAND" | |
return 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
aka moo="apt moo"