Files
dotfiles/local/bin/x-have

48 lines
720 B
Bash
Executable File

#!/usr/bin/env bash
# Returns which status
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
# Function to print usage information
usage()
{
echo "Usage: $0 <command>"
exit 1
}
# Function to print messages if VERBOSE is enabled
# $1 - message (string)
msg()
{
[[ "$VERBOSE" -eq 1 ]] && echo "$1"
return 0
}
# Function to check if a command exists
# $1 - command to check (string)
check_command()
{
local cmd=$1
if command -v "$cmd" > /dev/null 2>&1; then
msg "(*) '$cmd' is available on the system."
exit 0
else
msg "(!) '$cmd' is NOT available on the system."
exit 1
fi
}
# Main function
main()
{
if [ "$#" -ne 1 ]; then
usage
fi
check_command "$1"
}
main "$@"