DEV Community

Cover image for How I Set Up Aliases To Move Around SUPER FAST In The Terminal
Jessica Wang
Jessica Wang

Posted on

How I Set Up Aliases To Move Around SUPER FAST In The Terminal

I hate navigating directories in the terminal. Here are some examples of why:

  • Hard to remember the absolute path to certain files, like obscure config files.
  • Misspelling file names (I always type .zshrc wrong when in a hurry).
  • Having to cd & ls multiple times to find a relative path to the file in question.
  • Context-switching out of my project to find file path outside of my current setup.

Here’s my biggest hack to make navigating in the terminal files easy, fast, and painless.

The secret: Aliases.

Set up aliases for directories or files that you visit frequently. These can be:

1) Project-level directories that you visit frequently
(for example, switching between your work repo and person project repo).
2) Configuration files that you commonly need to edit
(For example, your .zshrc configuration file)
3) Scripts that you need to run as part of your development workflow
4) .txt files used to jot down notes on the fly
(For example, I use a .txt file to quickly track my calorie intake throughout the day)

With aliases, you type a lot less, don’t have to remember long file paths, and can avoid context-switching out of your current workflows.

Setup

In your command line, type in

vi ~/.zshrc

to start editing your .zshrc file.

If you’re in another shell like bash or fish, you’re going to need to edit their respective config files. But if you’re on a mac, the default shell should be zsh.

Your .zshrc file is where you can add any configuration for your zsh shell, like plugins, prompt customizations, and aliases.

In our case, we’re going to be adding some aliases. My setup is very simple.

# Put shortcuts to your paths here:
export DOCUMENTS=$HOME/Documents
export ZSHRC_CONFIG=$HOME/.zshrc
export STARSHIP_CONFIG=$HOME/.config/starship.toml
export THEMES=$DOCUMENTS/themes
export COMMANDS_DEV=$DOCUMENTS/commands.dev

# Put aliases for your scripts here:
alias deletess="~/Documents/scripts/delete_screenshots.sh"

# Put aliases for your config files here:
alias viz="nvim $ZSHRC_CONFIG"
alias vistarshipconfig="nvim $STARSHIP_CONFIG"

# Put aliases for your other commonly edited files here:
alias calories="nvim ~/Documents/Notes/calorie_tracker.txt"

# Put aliases for your directories here:
alias cdthemes="cd $THEMES"
alias cdcommandsdev="cd $COMMANDS_DEV"
Enter fullscreen mode Exit fullscreen mode

A few things to note about my setup:

  • You will need to replace all directories and files with your own file paths.
  • However, if you want to copy one alias from my setup, I suggest the “viz” alias. (Everybody needs to edit their ~/.zshrc file at some point!)
  • If you don’t have Neovim installed, then replace all instances “nvim” with “vi”.

After you’ve added your aliases, run

source ~/.zshrc

This will reload the .zshrc file in the current shell session and have your changes take effect without you having to restart your terminal session.

Now, try running one of your aliases. For example, if I run:

viz

It will automatically open up my ./zshrc file!

And that’s it. Thanks for reading 🙂

Let me know in the comments if there are any aliases I missed that you think are important!

Top comments (3)

Collapse
 
therubberduckiee profile image
Jessica Wang

Hey you're seeing this because you scrolled all the way down to the comment section. Give me a good movie recommendation.

Collapse
 
akhilproto profile image
AkhilProto • Edited

"The Wolf of Wall Street" and "The Social Network"... You can watch "Interstellar" once more too. These are currently in my "gotta watch for sure" list..

Collapse
 
akhilproto profile image
AkhilProto

Awesome!! I wanted to do this since a long time. You are a life saver!😄😄