Skip to content

Commit

Permalink
oh-my-bash: support OMB_VERSION and OMB_VERSINFO
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jan 19, 2022
1 parent 59a0bee commit 7dce520
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
2 changes: 0 additions & 2 deletions lib/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@

################################################################################

_omb_version=10000

function _omb_util_setexit {
return "$1"
}
Expand Down
4 changes: 4 additions & 0 deletions oh-my-bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 35 additions & 7 deletions tools/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
''
}

Expand All @@ -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 ;;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7dce520

Please sign in to comment.