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

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

check if the plugin is cloned correctly

Copy
ls ~/.oh-my-zsh/plugins

open .zshrc

Copy
open ~/.zshrc

or

Copy
vim ~/.zshrc

add zen-alias like this

Copy
# 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.
plugins=(
    git
    zen-alias
)

updating the plugin

Copy
cd <cloned directory> && git pull

Configure in bash


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

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

source the file in bashrc

Copy
open ~/.bashrc

add this line at the end of the bashrc

Copy
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.

Copy
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

Tips

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

Copy
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,

Copy
init_zen_dir: nvm use && rvm use
« (Setting up github custom domain)(You tried hard and you gave your best! still you failed and it's ok!) »