Skip to content

Instantly share code, notes, and snippets.

@james-prado
Last active May 24, 2025 02:05
Show Gist options
  • Select an option

  • Save james-prado/477165e36a796f74ea2bcadd23978c22 to your computer and use it in GitHub Desktop.

Select an option

Save james-prado/477165e36a796f74ea2bcadd23978c22 to your computer and use it in GitHub Desktop.

Shopify CLI Alias

Here's how to turn long Shopify CLI commands like

shopify theme dev --nodelete --ignore 'templates/*.json' 'config/settings_data.json' 'locales/en.default.json' 'sections/*.json' --store "$STORE" --theme "$THEME_ID"

into a simple alias like serve that's scoped to your project.

Prerequisites:

  • zsh*
    • Technically this will work for bash, fish, or any other shell – but I've written this guide specifically for zsh because that's what I use.
  • direnv
  • Shopify CLI

Local git ignore

To avoid constantly updating .gitignore files to accommodate personal configuration files or custom scripts, you can use git config core.excludesfile "path/to/file" to specify additional ignore files to use.

  1. Create a .gitignore_local file in the root of your project and paste add the following:
.gitignore_local
.envrc
.scripts/*
.zshrc
  1. (optional) Add this function into your ~/.zshrc file and use it quickly create and configure .gitignore_local files.
# set `git config -local core.excludesfile` to the `.gitignore_local` file the in working directory
localGitIgnore() {
	current_dir=$(pwd -P)
	if [[ ! -e ".gitignore_local" ]]; then
		touch .gitignore_local
	else
		if ! grep -q ".gitignore_local" "${current_dir}/.gitignore_local"; then
			echo "\n.gitignore_local" >>"${current_dir}/.gitignore_local"
		fi
	fi
	git config core.excludesfile "${current_dir}/.gitignore_local"
}

Environment variables

Environment variables are normally added to a .env file, but need to be loaded into the shell if you want to use them with the Shopify CLI. This is where direnv comes in. It takes care of loading and unloading environment variables for you.

  1. Install direnv
  2. Create a .envrc file in the root of your project, then define the THEME_ID and STORE variables
  3. Run direnv allow to load your environment variables.
    • Verify it's working by running echo $THEME_ID. It should output the theme id you just configured.

Shell scripts

  1. Create a .scripts/ directory in the root of your project
  2. Create a new shell script in the .scripts/ folder for each command you want to run. The most common scripts you'll need are:
  3. Verify the scripts work by running zsh .scripts/theme.sh

Scoped Aliases

You'll want to use these scripts across lots of different project, so they'll need to be scoped to each project directory.

  1. Create a .zshrc file in the root of your project and past the following
#!/usr/bin/bash
alias serve="zsh .scripts/serve.sh"
alias pull="zsh .scripts/pull.sh"
alias push="zsh .scripts/push.sh"
alias theme="zsh .scripts/theme.sh"
  1. Add the following code snippet to your global zsh file ~/.zshrc. This will automatically source any .zshrc file anytime you change directories:
# Source .zshrc files in the current directory
function _source_local_zshrc_files() {
	if [[ $PWD != $HOME ]]; then
		if [[ -r "$PWD/.zshrc" ]]; then
			source "$PWD/.zshrc"
			return 0
		else
			return 1
		fi
	fi
}

# Search for new .zshrc files to source when changing directories
function chpwd() {
	_source_local_zshrc_files
}

# Source .zshrc files on init
_source_local_zshrc_files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment