DEV Community

Cover image for Configuring Alias in macOS
Adithya Krishna
Adithya Krishna

Posted on

Configuring Alias in macOS

An alias helps you to produce a route name for a command, file name, or any shell text. By victimisation of aliases, you save heaps of your time once doing tasks that you were doing frequently.

What is an alias? 🤔

It's An Alias

The alias Korn shell integrated command to outline a phrase as an alias/shortcut for a few command. You can use aliases to redefine integrated or complex instructions except not to redefine reserved words.

Syntax:
alias [ -t ] [ -x ] [ AliasName [ =String ] ] ...

Flags:

  • -t - Sets or displays all existing tracked aliases
  • -x - Displays all existing exported alias definitions

Exit Status:

  • 0 - Success
  • >0 - An error occurred

Example 🙌🏻
alias gs='git status'

How to configure alias in macOS? 🧑🏻‍💻

  1. Open terminal
  2. Type code ~/.zshrc which opens the zsh config file in VSCode
  3. Configure your alias by following the above syntax and flags

Examples of my aliases:

alias gc='git commit -s -m'
alias gs='git status'
alias ga='git add'
alias gfu='git fetch upstream'
alias grum='git rebase upstream/master'
alias gpom='git push origin master'
alias gul='git fetch upstream && git rebase upstream/master && git push origin master'
alias gpo='git push origin'
Enter fullscreen mode Exit fullscreen mode
  1. Save the file by clicking cmd + s
  2. Now in your terminal, type source ~/.zshrc, which you applies the content of the file to the currently running Zsh process.

That's All

You are good to go 🎉

You can test your alias if its working by entering a repo in your machine and running gs

If you want to learn more about alias and its configuration, you can refer to, https://man7.org/linux/man-pages/man1/alias.1p.html#:~:text=An%20alias%20definition%20provides%20a,subshells%20of%20the%20current%20shell.

Top comments (0)