Skip to content

Instantly share code, notes, and snippets.

@ajcwebdev
Last active February 1, 2025 02:47
Show Gist options
  • Save ajcwebdev/69872bc66c2a480aaeea51469d730c4f to your computer and use it in GitHub Desktop.
Save ajcwebdev/69872bc66c2a480aaeea51469d730c4f to your computer and use it in GitHub Desktop.
Useful Snippets for MacOS Sequoia (15.2) with Apple M3 Pro Chip

Outline

Introduction and Other Resources

If you are not on a machine with an Apple M1 Chip be aware that there will be a few extraneous steps and commands throughout this gist. But for the most part if you ignore those commands and leave them out then mostly everything else should be fairly agnostic to Apple M1, Apple x86, or Linux.

Unfortunately, if you're on Windows you'll be hard pressed to find a single section of this gist that isn't broken or incompatible. On the bright side, that means you can write your own Useful Snippets gist for Windows users and you'll save a couple million people a few billion headaches.

Other good resources:

Install Developer Applications

Configure CLI

Install Homebrew and Brew Packages

Install and Configure Homebrew

After running the install script, we'll run a handful of commands to create a .zprofile file which will set the Homebrew path with shellenv. I also turn off analytics with the final command but that is not a required step.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"  # Install Homebrew
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> $HOME/.zprofile                      # Create .zprofile shell startup file with command to setup a Homebrew environment
cat $HOME/.zprofile                                                                              # Display contents of .zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"                                                        # Setup Homebrew environment in current terminal session
brew analytics off                                                                               # Turn off data collection for analytics
brew -v     # Check Homebrew version
brew -h     # Homebrew help command
brew config # Check Homebrew config
Install CLIs and Utility Packages with Homebrew
brew install oven-sh/bun/bun colima deno docker docker-compose docker-credential-helper ffmpeg flyctl gh httpstat jq pnpm railway tree webp yt-dlp

There are many ways to see what has been installed with Homebrew including commands such as list, deps, and leaves. To list top level brew packages and descriptions, run:

brew leaves | xargs -n1 brew desc --eval-all --formula

Install Volta and Node Packages

Install Volta and Node
curl https://get.volta.sh -s | bash  # Install Volta
volta install node@22  # Install Node 22
node -v                # Verify correct version of Node has been installed
Install Node CLIs with Volta
volta install tsx tsc

List all tools installed with Volta:

volta list

Other ways to inspect your Volta/Node/npm packages and general locally installed binaries:

ls /$HOME/.volta/bin                  # List all JavaScript packages installed and managed with Volta by inspecting `.volta/bin`
npm list --location=global --depth 0  # When installing all global Node packages through Homebrew/Volta, listing globally installed npm packages contains only `corepack` and `npm`
ls /usr/local/*                       # View binaries installed locally through specific shell script files instead of Homebrew/VoltaList
tree /usr/local/ -L 2                 # List locally installed binaries a different way

Inspect your Volta configuration file:

cat $HOME/.volta/tools/user/platform.json

Since I installed a specific legacy version of yarn and opted not to use Volta's experimental pnpm support (see GitHub Issue #737), this outputs the following on my machine:

{"node":{"runtime":"20.12.0","npm":null},"pnpm":null,"yarn":"1.22.22"}

Authenticate CLIs

Authenticate CLIs for GitHub, Railway, Netlify, Vercel, and Wrangler.
# Run `gh status` or `gh help` for more info
gh auth login

# Run `ntl status` or `ntl help` for more info
ntl login

# Run `vercel whoami` or `vercel help` for more info
vercel login

# Run `railway whoami`, `railway status`, or `railway help` for more info
railway login   # or `railway login --browserless` for browserless login

# TODO: wrangler login

Configure Git

Set name, email, default branch, and automatic remote pushing.
git config --global init.defaultBranch main
git config --global user.name "FIRST_NAME LAST_NAME"
git config --global user.email "[email protected]"
git config --global --add --bool push.autoSetupRemote true
git config --global http.postBuffer 524288000

The last configuration, http.postBuffer, increases the buffer size to 500 MB so pushes on repos over 50 MB don't fail. These changes can be seen in your .gitconfig file (scroll down to other attached files to see my .gitconfig file).

Common Workflows

Create and Push a Public GitHub Repo
mkdir github-cli-example
cd github-cli-example
echo '# GitHub CLI Example' >> README.md
git init
git add .
git commit -m "do the thing"
gh repo create github-cli-example \
  --public \
  --push \
  --source=. \
  --description="An example GitHub repo created and pushed to main with the GitHub CLI." \
  --remote=upstream
Deploy PostgreSQL Database with Railway
railway init -n example
railway add -p postgresql
railway open

Configure Aliases

Create aliases in .zshrc

Add the following lines of code to .zshrc:

alias ignore='echo ".DS_Store\nnode_modules\n.env\n.env.local" > .gitignore'
alias gs="git status"
alias gi="git init"
alias gc='git add . && git commit -m "commit"'
alias gp="git push"
alias t="tree -I node_modules -I whisper.cpp"
alias ls="ls -1"
alias ni='npm init -y && npm pkg set type="module"'
alias path='echo "$PATH" | tr ":" "\n" | nl'
  • ignore aliases to echo ".DS_Store\nnode_modules\n.env\n.env.local" > .gitignore for creating a custom .gitignore file that ignores .DS_Store for Mac users, node_modules for JavaScript projects, and .env/.env.local for sensitive API keys.
  • gi aliases to git init for initializing a Git repository
  • gs aliases to git status for checking the status of commits
  • gc aliases to git add . && git commit -m "commit" for automatically staging and committing changes (only use for solo projects where you do not wish to have meaningful commit messages to explain changes over time)
  • gp aliases to git push to push all new commits
  • t aliases to tree -I node_modules for printing a project's directory structure while ignoring any node_modules directories
  • ls aliases to ls -1 so files/directories displayed in the current working directory are listed one per line
  • ni aliases to a modification of npm init which runs npm pkg set type="module" to set type to module in package.json after initialization.
  • path aliases to echo "$PATH" | tr ":" "\n" | nl which displays an easily readable list of path variables instead of the single line of variables echo $0 outputs

Create Shell Functions

Current dotfiles (.zprofile, .zshrc, profile, and .gitconfig) are included at the bottom of the gist after the final DANGER section.

TODO: Better dotfile management.

DANGER - DO NOT RUN THESE UNLESS YOU KNOW WHAT YOU ARE DOING

Reset PATH to system default, uninstall/delete Homebrew/Volta and associated packages, and reset zsh dotfiles
# Reset PATH to default
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

# Delete Volta and all installed packages
rm -rf $HOME/.volta

# Uninstall Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

# If anything remains after uninstalling for some reason, you can delete the entire Homebrew directory
rm -rf /opt/homebrew

# Reset zsh dotfiles
rm -rf $HOME/.zprofile $HOME/.zshrc $HOME/.zsh_history $HOME/.zsh_sessions

Deprecated Setup Commands

Install Go and IPFS

No longer using Go or IPFS Kudo, migrating to Helia.

# Install Go
curl --remote-name https://dl.google.com/go/go1.20.4.darwin-arm64.pkg
sudo installer -pkg go1.20.4.darwin-arm64.pkg -target /
rm go1.20.4.darwin-arm64.pkg
go version # open new terminal and check go version
# Install IPFS Kudo
curl --remote-name https://dist.ipfs.tech/kubo/v0.16.0/kubo_v0.16.0_darwin-arm64.tar.gz
tar -xvzf kubo_v0.16.0_darwin-arm64.tar.gz
sudo bash kubo/install.sh
rm -rf kubo kubo_v0.16.0_darwin-arm64.tar.gz
ipfs --version # ipfs version 0.16.0
Install Rustup

Not installing right now cause Rust is cool but writing Rust is a lifestyle and I'm not ready for a long term commitment. And anyway, at this point shouldn't I just learn Zig instead?

curl https://sh.rustup.rs -sSf | sh  # Select 1) Proceed with installation (default)
source "$HOME/.cargo/env"
Install and Configure AWS CLI

No longer using AWS CLI cause YOLO.

curl --remote-name "https://awscli.amazonaws.com/AWSCLIV2.pkg" -s  # Download the AWS CLI installer
sudo installer -pkg AWSCLIV2.pkg -target /                         # Use the installer command to unzip the package
rm AWSCLIV2.pkg                                                    # Delete the installer package
aws configure                                                      # Configure AWS Access Key ID and Secret Access Key
aws --version                                                      # Check AWS CLI version
# Users/ajc/.gitconfig
[init]
# Sets the default branch name to "main" when initializing new repositories
defaultBranch = main
[user]
name = Anthony Campolo
email = [email protected]
[push]
# Sets up automatic remote tracking when pushing new branches, eliminates the need for '--set-upstream' or '-u'
autoSetupRemote = true
[filter "lfs"]
# Converts large files to LFS pointers when adding to Git
clean = git-lfs clean -- %f
# Converts LFS pointers back to actual files when checking out
smudge = git-lfs smudge -- %f
# Handles batch processing of LFS files for better performance
process = git-lfs filter-process
# Makes LFS mandatory for this repository
required = true
[http]
# Sets maximum size of HTTP POST requests to ~500MB, helpful when pushing large amounts of data with slow connections
postBuffer = 524288000
# Volta configuration
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"
# Homebrew initialization
eval "$(/opt/homebrew/bin/brew shellenv)"
# Users/ajc/.config/gh/config.yml
# The current version of the config schema
version: 1
# What protocol to use when performing git operations. Supported values: ssh, https
git_protocol: https
# What editor gh should run when creating issues, pull requests, etc. If blank, will refer to environment.
editor:
# When to interactively prompt. This is a global config that cannot be overridden by hostname. Supported values: enabled, disabled
prompt: enabled
# Preference for editor-based interactive prompting. This is a global config that cannot be overridden by hostname. Supported values: enabled, disabled
prefer_editor_prompt: disabled
# A pager program to send command output to, e.g. "less". If blank, will refer to environment. Set the value to "cat" to disable the pager.
pager:
# Aliases allow you to create nicknames for gh commands
aliases:
co: pr checkout
# The path to a unix socket through which send HTTP connections. If blank, HTTP traffic will be handled by net/http.DefaultTransport.
http_unix_socket:
# What web browser gh should use when opening URLs. If blank, will refer to environment.
browser:
# Users/ajc/.config/gh/hosts.yml
github.com:
git_protocol: https
users:
ajcwebdev:
user: ajcwebdev
@miwgel
Copy link

miwgel commented Apr 28, 2023

Very cool, thank you for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment