Auto-alias Your Repos

nickelkr

Kyle Nickel

Posted on January 25, 2020

Auto-alias Your Repos

If you have all your code repos under a common directory, you can make it so changing your working directory to any of the repos is just entering the name of the repo.

For example, all my code repos are under ~/code:

~ > ls ~/code
bar    foo
Enter fullscreen mode Exit fullscreen mode

By adding a loop for the sub-directories of the common parent inside your shell config, ~/.zshrc in my case, you can automatically create a alias for each of the repo directories:

for repo in $(ls ~/code)
do
  alias $repo="cd ~/code/$repo"
done
Enter fullscreen mode Exit fullscreen mode

Then you need to reload your config:

~ > . ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

Now, if you're in one repo, lets say foo:

~/code/foo/app/models >
Enter fullscreen mode Exit fullscreen mode

You can easily swap over to bar:

~/code/foo/app/models > bar
~/code/bar >
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
nickelkr
Kyle Nickel

Posted on January 25, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related