Local aliases using zen aliases

We can configure aliases very easily in bash or zsh. but those aliases are global to all directory. sometimes we need aliases or commands only for some directories alone. this plugin makes the process easy. those aliases will be available only to that particular directory. aliases will be loaded when you cd into the directory and unloaded once you leave the directory.

Configure in zsh

clone plugin from github

git clone https://github.com/Gokuldroid/zen-alias ~/.oh-my-zsh/plugins/zen-alias

check if the plugin is cloned correctly

ls ~/.oh-my-zsh/plugins

open .zshrc

open ~/.zshrc


vim ~/.zshrc

add zen-alias like this

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.

updating the plugin

cd <cloned directory> && git pull

Configure in bash

copy the file to root directory or somewhere in your system.

curl -S https://raw.githubusercontent.com/Gokuldroid/zen-alias/main/zen-alias.plugin.zsh > ~/.zen-alias.bash

source the file in bashrc

open ~/.bashrc

add this line at the end of the bashrc

source ~/.zen-alias.bash

Aliases syntax

Create .aliases file in the root directory of the project. add your per project aliases like this. You can find a sample file here.

yc: yarn w @zen-alias/client
ys: yarn w @zen-alias/server
ycommon: yarn w @zen-alias/common
ybg: yarn w @zen-alias/bg-jobs
yb: yarn build
yw: yarn watch


Excluding the .aliases file in git tree

incase if you don't want others to use your aliases, you can add it global .gitignore or project .gitignore

cd ~
touch .gitignore_global
git config --global core.excludesfile ~/.gitignore_global
echo ".aliases" > ~/.gitignore_global

Init command for a directory.

we might want to execute some script as soon as we enter the project. like updating local branch or setting up nvm or rvm version etc. zen-alias provides an easy way for this.

define a zen-alias like this,

init_zen_dir: nvm use && rvm use
(You tried hard and you gave your best! still you failed and it's ok!) »