---
title: "Where to Save Terminal Commands and Code Snippets on a Mac"
slug: save-terminal-commands-mac
url: https://refrainformac.com/guides/save-terminal-commands-mac
category: "Use Case"
published: 2026-11-04
updated: 2026-11-04
---

# Where to Save Terminal Commands and Code Snippets on a Mac

> Save commands you run every day as aliases in ~/.zshrc. Keep the ones you look up in a searchable snippet library instead. With Refrain, press Control-Option-Space in Terminal, type words from the command like "undo commit", press Return to copy it and Cmd-V to paste. Refrain only copies text, so nothing runs until you do.

## Why shell history isn't enough

Shell history is good at the command you ran ten minutes ago. It's bad at the one you run twice a year: the exact flags for a database dump, the ffmpeg line that worked, the git command that undoes the last commit without losing your changes. Those end up in a browser tab, a notes app, or nowhere.

There are two good homes for commands you reuse, and they cover different cases.

## Commands you run often: aliases

zsh is the default shell on current versions of macOS. For a command you run every day with the same arguments, give it a name in your `~/.zshrc`:

```
alias gs="git status -sb"
```

Open a new Terminal window and `gs` runs it. Aliases are ideal for a small set of fixed commands. They're a poor fit for commands with parts that change each time, and for the rare ones you won't remember the alias for anyway.

## Commands you look up: a snippet library

For everything else, keep the command text somewhere you can search and paste from. In Refrain:

1.  Press **Control-Option-Space** in Terminal (or any editor). A search palette opens.
2.  Type words you remember, from the name or the command itself: `undo commit`, `ffmpeg`, `dump`. Every word you type has to match, so two words usually find it.
3.  Press **Return** to copy it, then **Cmd-V** into the prompt. Edit the parts that change, then run it yourself.

Refrain only copies text. It never runs a command, so nothing executes until you press Return in Terminal. Multi-line scripts keep their line breaks.

One starter snippet ships with the app as an example: `git-undo-last-commit`, which copies `git reset --soft HEAD~1`.

## Store them as plain text

Refrain keeps snippets in one markdown file. Each snippet is a name plus the exact text that gets copied:

```
---
name: postgres-dump-one-table
---

pg_dump --data-only --table=TABLE_NAME DATABASE_NAME > table.sql

----
```

-   **Save the bare command.** The text is copied exactly as written, so leave out code fences and prompt characters like `$`.
-   **Mark the parts you change** in capitals, like `TABLE_NAME`, so they stand out after you paste.
-   **Name by task, not by tool:** `git-undo-last-commit` is easier to find later than `git-reset-soft`.

Tip

Keep the file in your dotfiles repo. You get version history, and every Mac you set up gets the same commands. The [sync guide](/guides/sync-snippets-between-macs) walks through pointing each Mac at one file.

## One place for commands and everything else

The same palette holds whatever else you paste during the day: AI prompts, review comments, email replies. If you work with coding agents, see [how to organize Claude Code prompts](/guides/organize-claude-code-prompts).

## Frequently asked questions

Where should I save terminal commands I use often on a Mac?

Commands you run daily with the same arguments work best as aliases in ~/.zshrc. Commands you only need now and then are better in a searchable snippet library like Refrain, where you find them by any word in the command.

Does Refrain run the command for me?

No. Refrain copies the text to the clipboard. You paste it into Terminal, edit anything that changes, and run it yourself.

Can I keep my code snippets in git?

Yes. Refrain stores snippets in one plain markdown file, so it can live in a dotfiles repo and be shared across Macs.

## FAQ

### Where should I save terminal commands I use often on a Mac?

Commands you run daily with the same arguments work best as aliases in ~/.zshrc. Commands you only need now and then are better in a searchable snippet library like Refrain, where you find them by any word in the command.

### Does Refrain run the command for me?

No. Refrain copies the text to the clipboard. You paste it into Terminal, edit anything that changes, and run it yourself.

### Can I keep my code snippets in git?

Yes. Refrain stores snippets in one plain markdown file, so it can live in a dotfiles repo and be shared across Macs.
