feat(explain): Add practical EXAMPLE section to demystify syntax
Added EXAMPLE section to explain mode with practical, simple examples for all commands.
Features:
- New get_practical_example() function with 50+ command examples
- EXAMPLE section appears after SYNTAX in same cyan/bold color
- Simple, real-world usage examples with inline comments
- Helps demystify overwhelming syntax options
Example Coverage:
- File operations: ls, cp, mv, rm, mkdir, chmod, etc.
- Text processing: grep, sed, awk, sort, uniq, etc.
- File search: find, locate, which
- Compression: tar, gzip, zip, unzip
- Network: ping, curl, wget, ssh, scp
- System info: top, ps, df, du, free
- Process management: kill, pkill
- Package management: apt, dpkg
- And more...
Format:
SYNTAX:
find [-H] [-L] [-P] [starting-point...] [expression]
EXAMPLE:
find . -name '*.txt' # Find all .txt files
Benefits:
- Reduces intimidation from complex syntax
- Shows most common use case
- Clear inline comments
- Instant practical reference
- Same professional styling as SYNTAX
User Request: 'add another section EXAMPLE: in same color as SYNTAX: using a practical simple example to demystify the sometimes overwhelming syntax options'
This commit is contained in:
@@ -431,6 +431,14 @@ mode_explain() {
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Add practical example
|
||||
echo -e "${CYAN}${BOLD}EXAMPLE:${NC}"
|
||||
local example=$(get_practical_example "$base_cmd")
|
||||
if [ -n "$example" ]; then
|
||||
echo -e " ${GREEN}$example${NC}"
|
||||
fi
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Try to find in database
|
||||
@@ -500,6 +508,88 @@ get_quick_syntax() {
|
||||
echo "$syntax"
|
||||
}
|
||||
|
||||
# Get practical example for a command
|
||||
get_practical_example() {
|
||||
local cmd="$1"
|
||||
local example=""
|
||||
|
||||
case "$cmd" in
|
||||
# File Operations
|
||||
ls) example="ls -lah # List all files with human-readable sizes";;
|
||||
cd) example="cd /path/to/directory # Change to a directory";;
|
||||
cp) example="cp file.txt backup.txt # Copy a file";;
|
||||
mv) example="mv old.txt new.txt # Rename or move a file";;
|
||||
rm) example="rm file.txt # Delete a file";;
|
||||
mkdir) example="mkdir new_folder # Create a new directory";;
|
||||
touch) example="touch newfile.txt # Create an empty file";;
|
||||
cat) example="cat file.txt # Display file contents";;
|
||||
chmod) example="chmod 755 script.sh # Make a script executable";;
|
||||
chown) example="chown user:group file # Change file owner";;
|
||||
ln) example="ln -s /path/to/file link # Create a symbolic link";;
|
||||
|
||||
# Text Processing
|
||||
grep) example="grep 'pattern' file.txt # Search for text in a file";;
|
||||
sed) example="sed 's/old/new/g' file # Replace text in a file";;
|
||||
awk) example="awk '{print \$1}' file # Print first column";;
|
||||
cut) example="cut -d',' -f1 file.csv # Extract first column from CSV";;
|
||||
sort) example="sort file.txt # Sort lines alphabetically";;
|
||||
uniq) example="sort file.txt | uniq # Remove duplicate lines";;
|
||||
wc) example="wc -l file.txt # Count lines in a file";;
|
||||
diff) example="diff file1.txt file2.txt # Compare two files";;
|
||||
|
||||
# File Search
|
||||
find) example="find . -name '*.txt' # Find all .txt files";;
|
||||
locate) example="locate filename # Quickly find a file";;
|
||||
which) example="which python # Show full path of command";;
|
||||
|
||||
# Compression
|
||||
tar) example="tar -czf archive.tar.gz folder/ # Compress a folder";;
|
||||
gzip) example="gzip file.txt # Compress a file";;
|
||||
gunzip) example="gunzip file.txt.gz # Decompress a file";;
|
||||
zip) example="zip archive.zip file1.txt file2.txt # Create zip archive";;
|
||||
unzip) example="unzip archive.zip # Extract zip archive";;
|
||||
|
||||
# Network
|
||||
ping) example="ping google.com # Test network connectivity";;
|
||||
curl) example="curl https://example.com # Download webpage";;
|
||||
wget) example="wget https://example.com/file.zip # Download a file";;
|
||||
ssh) example="ssh user@hostname # Connect to remote server";;
|
||||
scp) example="scp file.txt user@host:/path/ # Copy file to remote server";;
|
||||
|
||||
# System Info
|
||||
top) example="top # Monitor system processes";;
|
||||
ps) example="ps aux # List all running processes";;
|
||||
df) example="df -h # Show disk space usage";;
|
||||
du) example="du -sh folder/ # Show folder size";;
|
||||
free) example="free -h # Show memory usage";;
|
||||
uname) example="uname -a # Show system information";;
|
||||
|
||||
# Process Management
|
||||
kill) example="kill 1234 # Terminate process with PID 1234";;
|
||||
pkill) example="pkill firefox # Kill all firefox processes";;
|
||||
|
||||
# System Control
|
||||
sudo) example="sudo apt update # Run command as root";;
|
||||
systemctl) example="systemctl status nginx # Check service status";;
|
||||
|
||||
# Package Management
|
||||
apt) example="apt install package # Install a package";;
|
||||
dpkg) example="dpkg -i package.deb # Install .deb package";;
|
||||
|
||||
# Misc
|
||||
echo) example="echo 'Hello World' # Print text to screen";;
|
||||
date) example="date '+%Y-%m-%d' # Show current date";;
|
||||
history) example="history # Show command history";;
|
||||
man) example="man ls # Show manual for 'ls' command";;
|
||||
*)
|
||||
# Generic fallback
|
||||
example="$cmd --help # Show help for $cmd"
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "$example"
|
||||
}
|
||||
|
||||
# Extract all flags from man page or help
|
||||
extract_all_flags() {
|
||||
local cmd_name="$1"
|
||||
|
||||
Reference in New Issue
Block a user