From 7dce520857cb92ce66d485affca05c78677b1409 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sat, 15 Jan 2022 15:07:37 +0900 Subject: [PATCH] oh-my-bash: support OMB_VERSION and OMB_VERSINFO --- lib/utils.sh | 2 -- oh-my-bash.sh | 4 ++++ tools/install.sh | 42 +++++++++++++++++++++++++++++++++++------- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/lib/utils.sh b/lib/utils.sh index fdc6b41dd..a74f5a473 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -72,8 +72,6 @@ ################################################################################ -_omb_version=10000 - function _omb_util_setexit { return "$1" } diff --git a/oh-my-bash.sh b/oh-my-bash.sh index 4cffb3351..f00b2416c 100644 --- a/oh-my-bash.sh +++ b/oh-my-bash.sh @@ -21,6 +21,10 @@ if ((_omb_bash_version < 30200)); then return 1 fi +OMB_VERSINFO=(1 0 0 0 master noarch) +OMB_VERSION="${OMB_VERSINFO[0]}.${OMB_VERSINFO[1]}.${OMB_VERSINFO[2]}(${OMB_VERSINFO[3]})-${OMB_VERSINFO[4]} (${OMB_VERSINFO[5]})" +_omb_version=$((OMB_VERSINFO[0] * 10000 + OMB_VERSINFO[1] * 100 + OMB_VERSINFO[2])) + # Check for updates on initial load... if [[ $DISABLE_AUTO_UPDATE != true ]]; then source "$OSH"/tools/check_for_upgrade.sh diff --git a/tools/install.sh b/tools/install.sh index cda7d33c5..42c212753 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -17,20 +17,30 @@ elif ((BASH_VERSINFO[0] < 4)); then printf "Warning: Why don't you upgrade your Bash to 4 or higher?\n" >&2 fi +_omb_install_print_version() { + local OMB_VERSINFO + OMB_VERSINFO=(1 0 0 0 master noarch) + printf '%s\n' 'Install script for Oh-My-Bash (https://github.com/ohmybash/oh-my-bash)' + printf 'oh-my-bash, version %s.%s.%s(%s)-%s (%s)\n' "${OMB_VERSINFO[@]}" +} + _omb_install_print_usage() { printf '%s\n' \ - 'usage: ./install.sh [--unattended | --help | --dry-run]' \ - 'usage: bash -c "$(< install.sh)" [--unattended | --help | --dry-run]' + 'usage: ./install.sh [--unattended | --dry-run | --help | --usage | --version]' \ + 'usage: bash -c "$(< install.sh)" [--unattended | --dry-run | --help | --usage |' \ + ' --version]' } _omb_install_print_help() { + _omb_install_print_version _omb_install_print_usage printf '%s\n' \ - 'Install script for Oh-My-Bash (https://github.com/ohmybash/oh-my-bash)' \ '' \ 'OPTIONS' \ ' --help show this help' \ + ' --usage show usage' \ ' --unattended attend the meeting' \ + ' --help show version' \ '' } @@ -39,9 +49,12 @@ _omb_install_readargs() { local arg=$1; shift if [[ :$install_opts: != *:literal:* ]]; then case $arg in - --help | --unattended | --dry-run) + --help | --usage | --unattended | --dry-run) install_opts+=:${arg#--} continue ;; + --version | -v) + install_opts+=:version + continue ;; --) install_opts+=:literal continue ;; @@ -96,12 +109,27 @@ _omb_install_main() { local install_opts= _omb_install_readargs "$@" + if [[ :$install_opts: == *:error:* ]]; then + printf '\n' + install_opts+=:usage + fi if [[ :$install_opts: == *:help:* ]]; then _omb_install_print_help - return 0 - elif [[ :$install_opts: == *:error:* ]]; then - _omb_install_print_usage + install_opts+=:exit + else + if [[ :$install_opts: == *:version:* ]]; then + _omb_install_print_version + install_opts+=:exit + fi + if [[ :$install_opts: == *:usage:* ]]; then + _omb_install_print_usage + install_opts+=:exit + fi + fi + if [[ :$install_opts: == *:error:* ]]; then return 2 + elif [[ :$install_opts: == *:exit:* ]]; then + return 0 fi # Only enable exit-on-error after the non-critical colorization stuff,