diff --git a/ch b/ch old mode 100644 new mode 100755 index ed13153..7d640c6 --- a/ch +++ b/ch @@ -3,6 +3,31 @@ # catch uninitialized variables set -u + +# display basic usage information +display_basic_usage () +{ + echo "Usage: $0 [options]" + echo "Try '$0 --help' for more information." +} + + +# display detailed usage information +display_detailed_usage () +{ + echo "Usage: $0 [options]" + echo "Extract help information for a given command and its options." + echo + echo "Options:" + echo " --help Show this help message and exit." + echo + echo "Examples:" + echo " $0 ls --help" + echo " $0 grep --invert-match" + exit 0 +} + + ############################################### # extract from line starting with search word # upto newline or line starting with - @@ -24,6 +49,15 @@ extract_text () } +# Check for help option or no arguments +if [[ "$#" -eq 0 ]]; then + display_basic_usage + exit 1 +elif [[ "$1" == "--help" ]]; then + display_detailed_usage +fi + + ############################################### # variable to save command name # shift, for rest of arguments to be looped