Skip to content

Instantly share code, notes, and snippets.

@Khazbs
Created February 10, 2021 19:41
Show Gist options
  • Save Khazbs/923dea22873cee84a6a0ba25a2d7de36 to your computer and use it in GitHub Desktop.
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)
# 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
}
@Khazbs
Copy link
Author

Khazbs commented Feb 10, 2021

Example: aka moo="apt moo"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment