From a7aa456cd23a0bb307df0ca111f3d5ff76cfd68a Mon Sep 17 00:00:00 2001 From: priestlypython Date: Mon, 27 Oct 2025 20:19:45 -0700 Subject: [PATCH] Initial commit: Add bash-helper.sh with comprehensive documentation --- README.md | 168 ++++++++++++++++++++++++++++++++++++++++++++++++- bash-helper.sh | 64 +++++++++++++++++++ 2 files changed, 230 insertions(+), 2 deletions(-) create mode 100755 bash-helper.sh diff --git a/README.md b/README.md index 3c19266..f6dd43d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,167 @@ -# bash-buddy +# Bash Buddy -CLI assistant for impromptu bash scripting help \ No newline at end of file +🚀 CLI assistant for impromptu bash scripting help + +## Description + +Interactive bash command helper that uses `fzf` to browse common bash commands and their options. Perfect for when you need a quick reminder of command flags and usage without digging through man pages. + +## Features + +- 🔍 **Interactive Search** - Browse commands with fzf fuzzy finder +- 📖 **Command Descriptions** - Clear explanations for each command +- 🎯 **Flag Filtering** - Search for specific command options +- 🎨 **Color-Coded Output** - Easy-to-read terminal output +- 📚 **Smart Help** - Works with both built-in and external commands +- ⚡ **Quick Access** - Fast command reference at your fingertips + +## Dependencies + +```bash +# fzf - Fuzzy finder (required) +sudo apt install fzf # Ubuntu/Debian +brew install fzf # macOS +sudo pacman -S fzf # Arch +``` + +## Installation + +```bash +# Clone the repository +git clone http://localhost:3030/trill-technician/bash-buddy.git +cd bash-buddy + +# Make executable +chmod +x bash-helper.sh + +# Optional: Install system-wide +sudo cp bash-helper.sh /usr/local/bin/bash-helper + +# Or add to your PATH +echo 'export PATH="$HOME/bash-buddy:$PATH"' >> ~/.bashrc +source ~/.bashrc +``` + +## Usage + +```bash +./bash-helper.sh +``` + +### Workflow + +1. **Launch** - Run the script +2. **Browse** - Use arrow keys to navigate commands +3. **Select** - Press Enter to choose a command +4. **Filter** - Optionally enter a keyword to filter flags +5. **View** - See all available flags for the command + +### Example Session + +``` +$ ./bash-helper.sh + +> ls:List directory contents + cd:Change the current directory + pwd:Print the name of the current working directory + cp:Copy files and directories + mv:Move or rename files and directories + ... + +Command: ls +Description: List directory contents +Filter flags (optional): size + + Flags for ls: + -s, --size + print the allocated size of each file, in blocks + -S sort by file size, largest first + --block-size=SIZE + with -l, scale sizes by SIZE when printing them +``` + +## Included Commands + +The script includes help for these common bash commands: + +| Command | Description | +|---------|-------------| +| `ls` | List directory contents | +| `cd` | Change the current directory | +| `pwd` | Print working directory | +| `cp` | Copy files and directories | +| `mv` | Move or rename files | +| `rm` | Remove files or directories | +| `mkdir` | Create directories | +| `rmdir` | Remove empty directories | +| `grep` | Search text patterns | +| `find` | Search for files | +| `echo` | Display text | + +## Customization + +### Adding More Commands + +Edit the `COMMANDS` array in `bash-helper.sh`: + +```bash +COMMANDS=( + "command-name:Description of what it does" + "wget:Download files from the web" + "curl:Transfer data with URLs" + "tar:Archive files" + # Add your own... +) +``` + +### Changing Colors + +Modify the color variables at the top of the `show_flags()` function: + +```bash +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' # No Color +``` + +## How It Works + +1. **Command List** - Defines an array of common bash commands with descriptions +2. **FZF Selection** - Presents commands in an interactive fuzzy finder +3. **Help Extraction** - Retrieves flag information from: + - Built-in commands using `help` + - External commands using `man` pages +4. **Filtered Output** - Optionally filters flags based on your search term + +## Tips + +- Use partial matching in fzf (type any part of command name) +- Filter flags to find specific options quickly +- Add your most-used commands to the array +- Combine with aliases for even faster access + +```bash +# Add to ~/.bashrc +alias bh='bash-helper.sh' +``` + +## Contributing + +Feel free to: +- Add more commands to the default list +- Improve flag extraction logic +- Enhance the user interface +- Fix bugs or improve documentation + +## License + +MIT License - feel free to modify and distribute + +## Author + +Created as a quick reference tool for bash command-line work + +--- + +**Pro Tip**: Bookmark common flag patterns you discover, or add them as comments in the script for quick reference! diff --git a/bash-helper.sh b/bash-helper.sh new file mode 100755 index 0000000..a353593 --- /dev/null +++ b/bash-helper.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +show_help() { + echo "Usage: bash-helper [keyword]" + echo " + Searches for a keyword in a list of common bash commands and their explanations." + echo " + Options:" + echo " -h, --help Show this help message." +} + +show_flags() { + CMD_NAME=$1 + FILTER=$2 + + # Colors + RED='\033[0;31m' + GREEN='\033[0;32m' + YELLOW='\033[0;33m' + NC='\033[0m' # No Color + + echo -e " ${YELLOW}Flags for $CMD_NAME:${NC}" + + if type "$CMD_NAME" | grep -q "shell builtin"; then + if [ -n "$FILTER" ]; then + help "$CMD_NAME" | grep -E ' -' | grep -i "$FILTER" + else + help "$CMD_NAME" | grep -E ' -' + fi + elif command -v $CMD_NAME &> /dev/null; then + if [ -n "$FILTER" ]; then + man "$CMD_NAME" | col -b | grep -E ' -' | grep -i "$FILTER" + else + man "$CMD_NAME" | col -b | grep -E ' -' + fi + else + echo -e " ${RED}Could not find help for $CMD_NAME${NC}" + fi +} + +COMMANDS=( + "ls:List directory contents" + "cd:Change the current directory" + "pwd:Print the name of the current working directory" + "cp:Copy files and directories" + "mv:Move or rename files and directories" + "rm:Remove files or directories" + "mkdir:Create a new directory" + "rmdir:Remove an empty directory" + "grep:Print lines matching a pattern" + "find:Search for files in a directory hierarchy" + "echo:Display a line of text" +) + +FZF_COMMAND=$(printf "%s\n" "${COMMANDS[@]}" | fzf --height 40% --border --preview 'echo {}' --preview-window=up:1:wrap) + +if [ -n "$FZF_COMMAND" ]; then + CMD=${FZF_COMMAND%%:*} + EXP=${FZF_COMMAND#*:} + echo "Command: $CMD" + echo "Description: $EXP" + read -p "Filter flags (optional): " FILTER + show_flags "$CMD" "$FILTER" +fi