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

shorten npm command

Turbocharge Your Shopify CLI Workflow by creating a Speedy Alias

CLI shortcut dev ops tech tips shopify cli developer tools terminal hacks programming coding tips shell alias command line alias web development Linux zsh workflow optimization macOS terminal Bash productivity windows

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! 🚀


The Problem: Repetitive Typing Slows You Down 😩

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!


The Solution: A Simple CLI Alias! ✨

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!


How to Create Your Shopify CLI Alias (Platform-Specific Steps) 🖥️

Let's walk through the steps to set up this alias on your preferred operating system.


🪟 Windows (PowerShell)

PowerShell users, follow these instructions to create your alias.

  1. Find Your PowerShell Profile: Your PowerShell profile is a script that runs every time PowerShell starts. To find its location, open PowerShell and run:
    echo $PROFILE
    You'll typically see a path similar to C:\Users\<YourName>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1.
  2. Open or Create Your Profile Script: If the file doesn't exist, you'll need to create it. You can do this and then open it with Notepad:
    New-Item -Path $PROFILE -ItemType File -Force
    notepad $PROFILE
  3. Add the Alias: Inside the opened Notepad file, add the following line:
    Set-Alias s shopify
    Save the file and close Notepad.
  4. Reload or Restart PowerShell: For the changes to take effect, either restart your PowerShell terminal or run .& $PROFILE. Now, test your new alias:
    s --version
    You should see the Shopify CLI version number! 🎉

🍏 macOS (Zsh or Bash)

Most modern macOS systems use Zsh by default. Let's first confirm your shell.

  1. Check Your Shell: Open your terminal and run:
    echo $SHELL
    • If the output is /bin/zsh, follow the Zsh instructions.
    • If it's /bin/bash, follow the Bash instructions.

For Zsh Users:
  1. Edit Your Zsh Configuration: Open your .zshrc file in a text editor (like nano):
    nano ~/.zshrc
  2. Add the Alias: At the end of the file, add this line:
    alias s='shopify'
  3. Save and Exit: Press Ctrl + O (to write out), then Enter (to confirm the filename), and finally Ctrl + X (to exit nano).
  4. Apply Changes: For the alias to be active in your current terminal session, run:
    source ~/.zshrc
  5. Test It Out: Confirm your alias is working:
    s --version

For Bash Users:
  1. Edit Your Bash Configuration: Open your .bashrc file in a text editor:
    nano ~/.bashrc
  2. Add the Alias: Append the following line to the file:
    alias s='shopify'
  3. Save and Apply: Save the file (e.g., Ctrl + O, Enter, Ctrl + X in nano) and then reload your Bash configuration:
    source ~/.bashrc
    Your alias should now be ready to use!

🐧 Linux (Ubuntu/Debian/Arch & others)

The setup for Linux is very similar to macOS. You just need to identify whether you're using Bash or Zsh.

  1. Check Your Shell: Determine your active shell:
    echo $SHELL
    • If it's /bin/bash, you'll edit ~/.bashrc.
    • If it's /bin/zsh, you'll edit ~/.zshrc.
  2. Add the Alias: You can quickly add the alias and apply the changes in one go.
    • For Bash:
      echo "alias s='shopify'" >> ~/.bashrc
      source ~/.bashrc
    • For Zsh:
      echo "alias s='shopify'" >> ~/.zshrc
      source ~/.zshrc
  3. Confirm: To verify that your alias works, try a common command:
    s theme info
    You should see output from the Shopify CLI! 🎉

🧠 Pro Tip: Avoid Using 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.
  • Overriding it can lead to unexpected errors, break system scripts, or cause general instability.

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.


🚀 Summary: Your Quick Reference Guide

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'