Skip to content

archive-soniccc/my-shell-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

my-shell-scripts

A small collection of macOS zsh-friendly utilities to improve your shell workflow:

  • add_showpath_alias.sh: Adds a convenient showpath alias to print your PATH one 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.

Requirements

  • macOS with zsh (default on modern macOS)
  • No external dependencies required. Homebrew paths are recognized if present.

Installation

  1. 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
  1. Ensure ~/.local/bin is on your PATH (you can use clean_path.sh below to help). If needed, add this to ~/.zshrc:
export PATH="$HOME/.local/bin:$PATH"
  1. Reload your shell:
exec zsh

Scripts Overview & Usage

add_showpath_alias.sh

Adds an idempotent alias showpath line to your ~/.zshrc if it is not already present, then reloads your configuration.

  • What it adds: showpath prints your PATH one entry per line, numbered.
  • Usage:
add_showpath_alias.sh
  • Result: You can now run:
showpath

This helps you inspect your PATH clearly and spot duplicates or ordering issues.

clean_path.sh

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 in PATH).

  • Exports the cleaned PATH for the current session.

  • Optionally persists a managed block in ~/.zshrc delimited by markers, backing up your ~/.zshrc first if it exists.

  • Reloads ~/.zshrc only when the current shell is interactive; otherwise suggests exec zsh.

  • Usage:

clean_path.sh
  • Notes:
    • The persisted block uses zsh's typeset -U path PATH to keep PATH entries unique going forward.
    • A timestamped backup of ~/.zshrc is created on first run before appending the managed block.

newscript

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_tool

This 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 .sh if you supply it (so newscript my_tool.sh also 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.

script_template.sh

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 main function 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 date
  • Your Name → author name

Tips

  • After installing, run add_showpath_alias.sh once so you can use showpath when working on PATH issues.
  • Run clean_path.sh to quickly remove duplicates and persist a safe, order-aware configuration into ~/.zshrc.
  • Keep your personal scripts in ~/.local/bin and ensure it stays at the front of PATH.

Contributing

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages