Files
super-man/bash-helper.sh
T

65 lines
1.6 KiB
Bash
Executable File

#!/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