用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/majiayu000/claude-skill-registry --skill bash-cli-framework命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | bash-cli-framework |
| version | 1.0.0 |
| description | Universal bash CLI patterns for colors, logging, headers, and error handling |
| author | workspace-hub |
| category | bash |
| tags | ["bash","cli","colors","logging","framework","scripting"] |
| platforms | ["linux","macos"] |
A comprehensive framework for building consistent, professional bash CLI tools with standardized colors, logging, headers, and error handling patterns extracted from workspace-hub scripts.
✅ Use when:
❌ Avoid when:
Standard ANSI color codes for consistent terminal output:
#!/bin/bash
# ABOUTME: Standard color definitions for CLI output
# ABOUTME: Use these consistently across all workspace-hub scripts
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
# Bold variants
BOLD='\033[1m'
BOLD_RED='\033[1;31m'
BOLD_GREEN='\033[1;32m'
BOLD_YELLOW='\033[1;33m'
BOLD_BLUE='\033[1;34m'
# Usage examples
echo -e "${GREEN}✓ Success${NC}"
echo -e "${RED}✗ Error${NC}"
echo -e "${YELLOW}⚠ Warning${NC}"
echo -e "${CYAN}ℹ Info${NC}"
Every script should start with proper identification:
#!/bin/bash
# ABOUTME: Brief one-line description of what this script does
# ABOUTME: Additional context about usage or dependencies
set -e # Exit on error
# Script metadata
SCRIPT_NAME="$(basename "$0")"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VERSION="1.0.0"
Standardized logging with timestamps and levels:
#!/bin/bash
# ABOUTME: Logging framework for bash scripts
# ABOUTME: Supports DEBUG, INFO, WARNING, ERROR, CRITICAL levels
# Log file configuration
LOG_FILE="${LOG_FILE:-/tmp/${SCRIPT_NAME}.log}"
LOG_LEVEL="${LOG_LEVEL:-INFO}"
# Log level values
declare -A LOG_LEVELS=(
["DEBUG"]=0
["INFO"]=1
["WARNING"]=2
["ERROR"]=3
["CRITICAL"]=4
)
log() {
local level="$1"
shift
local message="$*"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
# Check if level meets threshold
if [[ ${LOG_LEVELS[$level]} -ge ${LOG_LEVELS[$LOG_LEVEL]} ]]; then
case "$level" in
DEBUG) echo -e "${CYAN}[${timestamp}] DEBUG${NC} - $message" ;;
INFO) echo -e "${GREEN}[${timestamp}] INFO${NC} - $message" ;;
WARNING) echo -e "[] WARNING - " ;;
ERROR) -e >&2 ;;
CRITICAL) -e >&2 ;;
>>
}
() { ; }
() { ; }
() { ; }
() { ; }
() { ; }
Professional header/banner display:
#!/bin/bash
# ABOUTME: Header and banner display functions
# ABOUTME: Creates consistent visual separation in CLI output
print_header() {
local title="$1"
local width="${2:-60}"
local char="${3:-═}"
local line=$(printf "%${width}s" | tr ' ' "$char")
echo ""
echo -e "${CYAN}${line}${NC}"
echo -e "${CYAN} ${title}${NC}"
echo -e "${CYAN}${line}${NC}"
echo ""
}
print_section() {
local title="$1"
echo ""
echo -e "${BOLD}${title}${NC}"
echo -e "${CYAN}$(printf '%.0s─' {1..40})"
}
() {
status=
message=
success) -e ;;
error) -e ;;
warning) -e ;;
info) -e ;;
pending) -e ;;
skip) -e ;;
}
Robust error handling with cleanup:
#!/bin/bash
# ABOUTME: Error handling and cleanup functions
# ABOUTME: Ensures graceful exit and resource cleanup
# Trap for cleanup on exit
cleanup() {
local exit_code=$?
# Remove temporary files
[[ -n "$TEMP_DIR" && -d "$TEMP_DIR" ]] && rm -rf "$TEMP_DIR"
# Log exit status
if [[ $exit_code -eq 0 ]]; then
log_info "Script completed successfully"
else
log_error "Script exited with code $exit_code"
fi
exit $exit_code
}
# Set trap
trap cleanup EXIT INT TERM
# Error handler
die() {
local message="$1"
local exit_code="${2:-1}"
log_critical "$message"
exit "$exit_code"
}
# Assert function
assert() {
local condition="$1"
local message="${2:-Assertion failed}"
! ;
die
}
Standard argument parsing pattern:
#!/bin/bash
# ABOUTME: Argument parsing framework
# ABOUTME: Supports short/long options with values
# Default values
VERBOSE=false
DRY_RUN=false
CONFIG_FILE=""
show_usage() {
cat << EOF
Usage: $SCRIPT_NAME [OPTIONS] <arguments>
Options:
-h, --help Show this help message
-v, --verbose Enable verbose output
-n, --dry-run Show what would be done without doing it
-c, --config FILE Use specified configuration file
--version Show version information
Examples:
$SCRIPT_NAME --verbose process
$SCRIPT_NAME -c config.yaml --dry-run
EOF
}
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
show_usage
exit 0
;;
-v|--verbose)
VERBOSE=true
LOG_LEVEL="DEBUG"
shift
;;
-n|--dry-run)
DRY_RUN=true
shift
;;
-c|--config)
CONFIG_FILE="$2"
shift 2
;;
--version)
echo "$SCRIPT_NAME version $VERSION"
exit 0
;;
--)
shift
break
;;
-*)
die "Unknown option: $1"
;;
*)
;;
ARGS=()
}
A complete script using all framework components:
#!/bin/bash
# ABOUTME: Example script demonstrating bash-cli-framework usage
# ABOUTME: Template for new CLI tools in workspace-hub
set -e
# ─────────────────────────────────────────────────────────────────
# Configuration
# ─────────────────────────────────────────────────────────────────
SCRIPT_NAME="$(basename "$0")"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VERSION="1.0.0"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
# Defaults
VERBOSE=false
DRY_RUN=false
LOG_LEVEL="INFO"
# ─────────────────────────────────────────────────────────────────
# Functions
# ─────────────────────────────────────────────────────────────────
log_info() { echo -e "${GREEN}[INFO]${NC} $*"; }
log_warning() { echo -e "${YELLOW}[WARN]${NC} $*"; }
log_error() { echo -e "${RED}[ERROR] $*" >&2; }
() { log_error ; ; }
() {
-e
-e
-e
}
() {
<<
}
() {
exit_code=$?
[[ == ]] && log_info
}
cleanup EXIT INT TERM
() {
[[ -gt 0 ]];
-h|--) show_usage; 0 ;;
-v|--verbose) VERBOSE=; ;;
-n|--dry-run) DRY_RUN=; ;;
--version) ; 0 ;;
-*) die ;;
*) ;;
=
[[ -z ]] && { show_usage; die ; }
print_header
run)
log_info
[[ == ]] && log_warning
;;
status)
log_info
;;
clean)
log_info
;;
*)
die
;;
log_info
}
main
set -eExit immediately if a command exits with non-zero status:
set -e
# Or for more control:
set -euo pipefail
Always quote variables to prevent word splitting:
# Good
echo "$variable"
"$command" "$arg1" "$arg2"
# Bad
echo $variable
$command $arg1 $arg2
# Exit codes
EXIT_SUCCESS=0
EXIT_ERROR=1
EXIT_USAGE=2
EXIT_CONFIG=3
Always tell the user what's happening:
log_info "Starting process..."
# do work
log_info "Process complete (processed $count items)"
Let users preview changes:
if [[ $DRY_RUN == true ]]; then
log_info "[DRY RUN] Would execute: $command"
else
eval "$command"
fi
This framework is used across all workspace-hub scripts:
scripts/monitoring/suggest_model.shscripts/monitoring/check_claude_usage.shscripts/workspacescripts/repository_sync