How to Create a Command-Line Alias (Windows/macOS/Linux)

Writing the same command again and again is boring and time consuming, so let me show you how you can use alias and shorten your CLI command across Windows, macOS, and Linux. For example, we will shorten the shopify cli command today. You can follow this guide and shorten any command you want. Let's dive in! 🚀
If you're deep in Shopify development, you're probably running commands like these all the time:
shopify theme dev
shopify login
shopify app create
Each shopify
adds unnecessary characters and slows down your rhythm. This seemingly minor inefficiency adds up, especially when you're juggling multiple projects or automating tasks. Imagine how much faster you'd be if you could skip that prefix!
A shell alias is a powerful feature that lets you define a shorthand for a longer command. For instance, you can map shopify
to a single letter like s
:
alias s='shopify'
Once set, this means you can execute Shopify CLI commands with far fewer keystrokes:
s theme dev # This is the same as 'shopify theme dev'
s login # This is the same as 'shopify login'
It's a small change with a big impact on your daily productivity!
Let's walk through the steps to set up this alias on your preferred operating system.
PowerShell users, follow these instructions to create your alias.
echo $PROFILE
You'll typically see a path similar to C:\Users\<YourName>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
. New-Item -Path $PROFILE -ItemType File -Force
notepad $PROFILE
Set-Alias s shopify
Save the file and close Notepad. .& $PROFILE
. Now, test your new alias:s --version
You should see the Shopify CLI version number! 🎉 Most modern macOS systems use Zsh by default. Let's first confirm your shell.
echo $SHELL
/bin/zsh
, follow the Zsh instructions. /bin/bash
, follow the Bash instructions. .zshrc
file in a text editor (like nano
):nano ~/.zshrc
alias s='shopify'
Ctrl + O
(to write out), then Enter
(to confirm the filename), and finally Ctrl + X
(to exit nano
). source ~/.zshrc
s --version
.bashrc
file in a text editor:nano ~/.bashrc
alias s='shopify'
Ctrl + O
, Enter
, Ctrl + X
in nano
) and then reload your Bash configuration:source ~/.bashrc
Your alias should now be ready to use! The setup for Linux is very similar to macOS. You just need to identify whether you're using Bash or Zsh.
echo $SHELL
/bin/bash
, you'll edit ~/.bashrc
. /bin/zsh
, you'll edit ~/.zshrc
. echo "alias s='shopify'" >> ~/.bashrc
source ~/.bashrc
echo "alias s='shopify'" >> ~/.zshrc
source ~/.zshrc
s theme info
You should see output from the Shopify CLI! 🎉 sh
as Your Alias!While s
is a great choice, you might be tempted to use sh
as your alias. Don't do it! 🛑
sh
is a reserved system command that points to the Bourne shell. Stick to safe, intuitive aliases like:
s
(most common and fastest) scli
(for "Shopify CLI") spfy
(a shorter version of "Shopify") Choose whatever feels most natural and won't conflict with existing commands.
Here's a handy table summarizing where to add your alias on each platform:
OS | Configuration File | Alias Command |
---|---|---|
Windows | $PROFILE | Set-Alias s shopify |
macOS | ~/.zshrc or ~/.bashrc | alias s='shopify' |
Linux | ~/.zshrc or ~/.bashrc | alias s='shopify' |