Skip to content

Instantly share code, notes, and snippets.

@prathik
Created January 5, 2016 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save prathik/7ba3e7e9933063d7f7a4 to your computer and use it in GitHub Desktop.
Save prathik/7ba3e7e9933063d7f7a4 to your computer and use it in GitHub Desktop.
create alias, make alias and remove alias shortcut for zsh
alias showalias='cat ~/.zsh_alias'
#Add source ~/.zsh_alias in your ~/.zshrc
#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'" >> ~/.zsh_alias
source ~/.zshrc
}
# 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>> ~/.zsh_alias;
source ~/.zshrc;
fi
}
# ra aliasname removes the alias
removeAlias()
{
sed -i "/^alias $1/d" ~/.zsh_alias;
unalias $1;
source ~/.zshrc;
}
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