diff --git a/profile.d/info.sh b/profile.d/info.sh index d2f23a7..68a8440 100644 --- a/profile.d/info.sh +++ b/profile.d/info.sh @@ -39,6 +39,27 @@ # Usage: ver ver() { + local PARSED=$(getopt -o h --long help -n 'ver' -- "$@") + if [[ $? -ne 0 ]]; then + disp E "Invalid options, use \"ver --help\" to display usage." + return 1 + fi + eval set -- "$PARSED" + case "$1" in + -h|--help) + printf "ver: Display the current profile version.\nUsage: ver\n" + return 0 + ;; + --) + shift + break + ;; + *) + disp E "Invalid options, use \"ver --help\" to display usage." + return 1 + ;; + esac + [[ -z $PROFVERSION ]] && \ disp W "No version defined. Profile is probably badly installed." && \ return 1 @@ -53,7 +74,28 @@ export -f ver # Usage: meteo [city1 city2 ...] meteo() { - local encoded cities=("$@") + local PARSED=$(getopt -o h --long help -n 'meteo' -- "$@") + if [[ $? -ne 0 ]]; then + disp E "Invalid options, use \"meteo --help\" to display usage." + return 1 + fi + eval set -- "$PARSED" + case "$1" in + -h|--help) + printf "meteo: Fetch weather data.\nUsage: meteo [city1 city2 ...]\n" + return 0 + ;; + --) + shift + break + ;; + *) + disp E "Invalid options, use \"meteo --help\" to display usage." + return 1 + ;; + esac + + local cities=("$@") [[ $# -eq 0 ]] && cities=("$DEFAULT_CITY") for city in "${cities[@]}"; do @@ -71,7 +113,27 @@ export -f meteo # Usage: showinfo showinfo() { - echo -e "\n" + local PARSED=$(getopt -o h --long help -n 'showinfo' -- "$@") + if [[ $? -ne 0 ]]; then + disp E "Invalid options, use \"showinfo --help\" to display usage." + return 1 + fi + eval set -- "$PARSED" + case "$1" in + -h|--help) + printf "showinfo: Display system information (hostname, kernel, uptime).\nUsage: showinfo\n" + return 0 + ;; + --) + shift + break + ;; + *) + disp E "Invalid options, use \"showinfo --help\" to display usage." + return 1 + ;; + esac + printf "\n" if command -v figlet >/dev/null 2>&1; then if [[ -s /usr/share/figlet/ansi_shadow.flf ]]; then local figopt="-f ansi_shadow" @@ -94,11 +156,11 @@ showinfo() if [[ -s /etc/os-release ]]; then # shellcheck disable=SC1091 . /etc/os-release - echo "$NAME $VERSION" + printf "$NAME $VERSION\n" else cat /proc/version fi - echo "Uptime: $(uptime -p)" + printf "Uptime: $(uptime -p)\n" ) fi } @@ -106,4 +168,5 @@ export -f showinfo # ------------------------------------------------------------------------------ +load_conf info # EOF