mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-06-20 19:57:46 +02:00
Fix lib/opt.sh not working on Bash 5 (#2)
This commit is contained in:
parent
85bb5f8bed
commit
5749d9ea2d
17
lib/opt.sh
17
lib/opt.sh
@ -7,6 +7,13 @@
|
||||
# -----------------------------------------------------------------------------
|
||||
PROGRAM="$(basename "${BASH_SOURCE[0]}")"
|
||||
|
||||
# Sets the internal _ARGV and _ARGV_INDEX variables used when
|
||||
# parsing options with the shiftopt and shiftval functions.
|
||||
setargs() {
|
||||
_ARGV=("$@")
|
||||
_ARGV_INDEX="$((${#_ARGV[@]} - 1))"
|
||||
}
|
||||
|
||||
# Gets the next option passed to the script.
|
||||
#
|
||||
# Variables:
|
||||
@ -22,12 +29,6 @@ PROGRAM="$(basename "${BASH_SOURCE[0]}")"
|
||||
# echo "$OPT = $OPT_VAL"
|
||||
# done
|
||||
shiftopt() {
|
||||
# Ensure _ARGV exists and has the program arguments.
|
||||
if [[ -z ${_ARGV+x} ]]; then
|
||||
_ARGV=("${BASH_ARGV[@]}")
|
||||
_ARGV_INDEX="$((${#_ARGV[@]} - 1))"
|
||||
fi
|
||||
|
||||
# Read the top of _ARGV.
|
||||
[[ "$_ARGV_INDEX" -lt 0 ]] && return 1
|
||||
OPT="${_ARGV[$_ARGV_INDEX]}"
|
||||
@ -67,3 +68,7 @@ shiftval() {
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
setargs "$@"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user