Skip to content

Instantly share code, notes, and snippets.

@NathanaelGandhi
Last active June 8, 2023 23:31
Show Gist options
  • Save NathanaelGandhi/015ff05c6d06fab6806f7c58f9e8beef to your computer and use it in GitHub Desktop.
Save NathanaelGandhi/015ff05c6d06fab6806f7c58f9e8beef to your computer and use it in GitHub Desktop.
help functionality for shell scripts
#!/bin/bash -eu
# author: Nathanael Gandhi
# github.com/NathanaelGandhi
################################################################################
# Source required functions #
################################################################################
bash_utils_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/bash_utils"
mkdir -p "$bash_utils_dir"
echo " • Sourcing required functions"
{
script_name=bash-function-forceRoot.sh
gist_url=https://gist.github.com/NathanaelGandhi/96f735c0906c15b69a2de6b4d6561d76/raw
if [ ! -e "$bash_utils_dir/$script_name" ]; then
# If the file doesn't exist, download it with wget
echo " • Downloading: $script_name to $bash_utils_dir/"
output_file=$script_name
wget -O "$bash_utils_dir/$output_file" "$gist_url"
fi
# Now the file exists, source it
. $bash_utils_dir/$script_name
echo " • Sourced: $script_name"
}
################################################################################
# check input args #
################################################################################
checkInputArgs()
{
# get the options
while getopts ":h" option; do
case $option in
h) # display Help
Help
exit;;
\?) # incorrect option
echo "Error: Invalid option. Use -h for help"
exit;;
esac
done
}
################################################################################
# help #
################################################################################
help()
{
# display help description
echo "Add description of the script functions here."
echo
echo "Syntax: scriptTemplate [-h]"
echo "options:"
echo "h Print this Help."
echo
}
################################################################################
################################################################################
# main #
################################################################################
################################################################################
checkInputArgs
# continue script here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment