Skip to content

Instantly share code, notes, and snippets.

@prathik
Last active August 29, 2015 14:03
Show Gist options
  • Save prathik/7c27000fa8a6e2688f76 to your computer and use it in GitHub Desktop.
Save prathik/7c27000fa8a6e2688f76 to your computer and use it in GitHub Desktop.
Alias code with remove alias
alias showalias='cat ~/.bash_aliases'
#Type ma <aliasname> in a directory and it will create an alias to cd into that directory
makeAlias()
{
curDir=`pwd`
echo "alias $1='cd $curDir'" >> ~/.bash_aliases
source ~/.bashrc
}
# ca "aliasname='<command>'" creates an alias aliasname for the command given
customAlias()
{
storeString="alias $1"
echo $storeString
read -p "Do you wish to save this alias? [y/n]" yn
if [ "$yn" = "y" ]; then
echo $storeString>> ~/.bash_aliases;
source ~/.bashrc;
fi
}
# ra aliasname removes the alias
removeAlias()
{
sed -i "/^alias $1/d" ~/.bash_aliases;
unalias $1;
source ~/.bashrc;
}
alias ma=makeAlias
alias ca=customAlias
alias ra=removeAlias
#To see the expansion of an alias use `type <alias>`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment