Skip to content

tigger04/shell-and-scripting-helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shell and Scripting Helpers

Introduction

A collection of bash shell functions and utilities focused on performance and practical daily use. These scripts avoid expensive subshells where possible and provide consistent visual feedback.

Quick Start

git clone https://github.com/YOUR_GITHUB_USERNAME/shell-and-scripting-helpers.git
cd shell-and-scripting-helpers
./install-me

Add to your ~/.bashrc (for macOS ~/.bash_profile), -or- or add to taste, to any script you wish to use a particular function in:

source ~/.qfuncs.sh  # functions that are useful for scripting
source ~/.emojis.sh  # emoji shortcode support
source ~/.colours.sh  # ANSI colours, using human readable variable names
[[ $- == *i* ]] && source ~/.clifuncs.sh  # useful interactive (terminal) functions
                                          # (only load for interactive shells)
  • Package manager: Homebrew (macOS) or APT (Linux - assuming Debian/Ubuntu family)

Bash 5 Installation (main dependency)

Bash 5 is standard in modern Linux and Windows Subsystem for Linux, but macOS comes with an older version, so upgrade if necessary.

macOS:

brew install bash

Installation

The install-me script:

  1. Detects your operating system and package manager
  2. Checks for Bash 5+ compatibility
  3. Scans for missing dependencies and offers to install them
  4. Creates symlinks in your $HOME directory for all script files

Dependencies

  • ripgrep - fast recursive text search
  • fd - modern, fast find alternative
  • bat - replacement for cat with syntax highlighting
  • tldr - simplified quick and dirty help/man page alternative
  • yt-dlp - YouTube downloader
  • lsd - modern ls with colors
  • trash - safe file deletion
  • fzf - fuzzy finder
  • coreutils - more powerful versions of cp, mv, and rm, rsync, and more (standard on modern Linux, available via Homebrew on macOS)

Platform Support

  • macOS: Uses Homebrew
  • Linux: Uses apt (Debian/Ubuntu). Other distributions require manual dependency installation.
  • Windows: via WSL (Windows Subsystem for Linux)

Files

.qfuncs.sh - Core Utilities

Performance-optimized functions for common tasks:

  • die() - Error handling
  • warn(), info() - Standardized messaging (outputs to stderr, safe for piping)
  • qbase() - Fast basename/dirname without subshells
  • fullpath() - Resolve absolute paths using built-in shell functionality (fast)
  • timestamp(), datestamp() - Date/time utilities
  • confirm_continue() - Interactive confirmation prompts
  • show_cmd_execute, confirm_cmd_execute - Command execution/confirmation
  • more …

.emojis.sh - Emoji Support

Associative array mapping GitHub emoji shortcodes to Unicode:

echo "${moji[thumbs_up]}"  # 👍
# or
moji thumbs_up

.colours.sh - ANSI Colors

ANSI escape sequences mapped to human readable variable names.

.clifuncs.sh - Interactive Functions

Command-line tools and aliases:

  • mkcd() - Make directory and cd into it
  • trash() - Safe file deletion
  • rgg(), rgw(), rw() - Ripgrep wrappers
  • help() - Enhanced help using tldr and bat
  • Git aliases: s (status), commit(), pull(), etc.

Usage Examples

Messaging, informative processing, etc

info "Starting process..."
warn "This might take a while" 
dodgy_command || die "Something went wrong"
show_cmd_execute ls -l /some/path

Path Operations

qbase "/path/to/file.txt" basename dirname
fullpath "relative/path" result

Confirmations

confirm_continue "Delete files?" || exit 1
# or
confirm_cmd_execute rm file

Design Principles

  • Performance: Avoid subshells which slow down execution
  • Consistency: user output goes to stderr to preserve pipes
  • Safety: Input validation and confirmation prompts
  • Portability: Works on macOS and Linux with graceful degradation

Troubleshooting

Manual Dependency Installation

macOS:

brew install ripgrep fd bat tldr yt-dlp lsd trash fzf coreutils

Debian/Ubuntu:

sudo apt install ripgrep fd-find bat tldr yt-dlp lsd trash-cli fzf

Common Issues

  • Functions requiring specific tools will fail gracefully if dependencies are missing
  • On macOS, git status functions require gstat from coreutils
  • Linux users with non-APT package managers need to install dependencies manually

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Test on both macOS and Linux
  4. Ensure bash 5+ compatibility
  5. Submit a pull request

License

MIT License

About

Helper functions for bash shell scripting

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages