A small collection of macOS zsh-friendly utilities to improve your shell workflow:
- add_showpath_alias.sh: Adds a convenient
showpathalias to print yourPATHone entry per line (numbered). - clean_path.sh: Audits and de-duplicates your
PATH, prefers common user and Homebrew directories, and persists a managed block in~/.zshrc. - newscript: Creates a new script from a template into
~/.local/bin, fills in metadata, makes it executable, and opens it in Cursor. - script_template.sh: The template used by
newscript.
- macOS with zsh (default on modern macOS)
- No external dependencies required. Homebrew paths are recognized if present.
- Clone or copy these files locally, then install into
~/.local/bin:
mkdir -p ~/.local/bin
cp add_showpath_alias.sh clean_path.sh newscript script_template.sh ~/.local/bin/
chmod +x ~/.local/bin/add_showpath_alias.sh ~/.local/bin/clean_path.sh ~/.local/bin/newscript ~/.local/bin/script_template.sh- Ensure
~/.local/binis on yourPATH(you can useclean_path.shbelow to help). If needed, add this to~/.zshrc:
export PATH="$HOME/.local/bin:$PATH"- Reload your shell:
exec zshAdds an idempotent alias showpath line to your ~/.zshrc if it is not already present, then reloads your configuration.
- What it adds:
showpathprints yourPATHone entry per line, numbered. - Usage:
add_showpath_alias.sh- Result: You can now run:
showpathThis helps you inspect your PATH clearly and spot duplicates or ordering issues.
Audits and cleans your current PATH:
-
Reports duplicates (with counts).
-
De-duplicates while preserving the first occurrence order.
-
Prefers and prepends common user and Homebrew directories:
~/.local/bin,~/bin,/opt/homebrew/bin,/opt/homebrew/sbin(only if they are not already earlier inPATH). -
Exports the cleaned
PATHfor the current session. -
Optionally persists a managed block in
~/.zshrcdelimited by markers, backing up your~/.zshrcfirst if it exists. -
Reloads
~/.zshrconly when the current shell is interactive; otherwise suggestsexec zsh. -
Usage:
clean_path.sh- Notes:
- The persisted block uses zsh's
typeset -U path PATHto keepPATHentries unique going forward. - A timestamped backup of
~/.zshrcis created on first run before appending the managed block.
- The persisted block uses zsh's
Creates a new script in ~/.local/bin from script_template.sh, fills in the script name, date, and author, makes it executable, and opens it for editing (Cursor preferred, falls back to nano).
- Usage:
newscript my_toolThis produces ~/.local/bin/my_tool.sh from the template, with placeholders replaced. The command refuses to overwrite an existing file of the same name.
- Behavior details:
- Strips a trailing
.shif you supply it (sonewscript my_tool.shalso works). - Uses macOS/BSD
sed -i ''for in-place edits. - Attempts to open the new script in Cursor; if Cursor is not installed, opens in
nano.
- Strips a trailing
The base template for new scripts. It includes:
- zsh shebang and safe shell defaults (
set -euo pipefail) - Consistent logging helpers (
log_info,log_success,log_warn,log_error) - A
mainfunction with a clear section to place your script's logic
Placeholders are replaced by newscript:
<script_name>→ your chosen script name<YYYY-MM-DD>→ current dateYour Name→ author name
- After installing, run
add_showpath_alias.shonce so you can useshowpathwhen working onPATHissues. - Run
clean_path.shto quickly remove duplicates and persist a safe, order-aware configuration into~/.zshrc. - Keep your personal scripts in
~/.local/binand ensure it stays at the front ofPATH.
Issues and improvements are welcome. Feel free to submit pull requests that:
- Improve safety, portability, or clarity
- Enhance logging and UX
- Add useful, small shell utilities following the same style