Ensure to manage eza's options
Append options to EZA_OPTIONS var. Pass the EZA_OPTIONS var to eza with an `echo`. Avoid conflict with eza's options.
This commit is contained in:
parent
dd4cb4ca1a
commit
c4bb17db4f
72
eza
72
eza
|
@ -46,7 +46,7 @@ readonly COLOR_DEBUG="${PURPLE}"
|
||||||
usage() { # {{{
|
usage() { # {{{
|
||||||
|
|
||||||
cat <<- HELP
|
cat <<- HELP
|
||||||
usage: $PROGNAME [-d|-h|-u|-s]
|
usage: $PROGNAME [--debug|help|--user|--system]
|
||||||
|
|
||||||
Tiny script to start existing eza (from the system or from user's PATH)
|
Tiny script to start existing eza (from the system or from user's PATH)
|
||||||
|
|
||||||
|
@ -55,22 +55,24 @@ EXAMPLES :
|
||||||
${PROGNAME}
|
${PROGNAME}
|
||||||
|
|
||||||
- Set different binary for user
|
- Set different binary for user
|
||||||
${PROGNAME} -u "${HOME}/bin/my.eza"
|
${PROGNAME} --user "${HOME}/bin/my.eza"
|
||||||
|
|
||||||
OPTIONS :
|
OPTIONS :
|
||||||
-d,--debug
|
--debug
|
||||||
Enable debug messages.
|
Enable debug messages.
|
||||||
|
|
||||||
-h,--help
|
help
|
||||||
Print this help message.
|
Print this help message.
|
||||||
|
|
||||||
-u,--user
|
--user
|
||||||
Change the user's binary to use.
|
Change the user's binary to use.
|
||||||
(default: ${EZA_USER_PATH})
|
(default: ${EZA_USER_PATH})
|
||||||
|
|
||||||
-s,--system
|
--system
|
||||||
Change the system's binary to use.
|
Change the system's binary to use.
|
||||||
(default: ${EZA_SYSTEM_PATH})
|
(default: ${EZA_SYSTEM_PATH})
|
||||||
|
|
||||||
|
ALL OTHER OPTIONS WILL BE PASSED AS EZA's OPTIONS
|
||||||
HELP
|
HELP
|
||||||
}
|
}
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -155,19 +157,46 @@ main() { # {{{
|
||||||
## If eza system is available {{{
|
## If eza system is available {{{
|
||||||
### Start it
|
### Start it
|
||||||
if is_bin_present "${eza_system_path}" "| "; then
|
if is_bin_present "${eza_system_path}" "| "; then
|
||||||
debug_message "Use Eza from system (${eza_system_path})"
|
### If EZA_OPTIONS is defined, call eza with options {{{
|
||||||
"${eza_system_path}" \
|
if [ -n "${EZA_OPTIONS-}" ]; then
|
||||||
|| error_message "Error while calling eza from system path (${eza_system_path})" 11
|
debug_message "Use Eza from system (${eza_system_path}) with options (${EZA_OPTIONS})."
|
||||||
|
"${eza_system_path}" $(echo "${EZA_OPTIONS}") \
|
||||||
|
|| error_message "Error while calling eza from system path (${eza_system_path})" 11
|
||||||
|
### }}}
|
||||||
|
### If EZA_OPTIONS is NOT defined simply call it {{{
|
||||||
|
elif [ -z "${EZA_OPTIONS-}" ]; then
|
||||||
|
debug_message "Use Eza from system (${eza_system_path}) without options."
|
||||||
|
"${eza_system_path}" \
|
||||||
|
|| error_message "Error while calling eza from system path (${eza_system_path})" 12
|
||||||
|
### }}}
|
||||||
|
### If anything else happens, exit with error {{{
|
||||||
|
else
|
||||||
|
error_message "This test case is not supposed to happen ! Variable EZA_OPTIONS is defined or not." 13
|
||||||
|
fi
|
||||||
|
### }}}
|
||||||
debug_message "--- MAIN END"
|
debug_message "--- MAIN END"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
## }}}
|
## }}}
|
||||||
## If eza from user path is available {{{
|
## If eza from user path is available {{{
|
||||||
### Start it
|
|
||||||
if is_bin_present "${eza_user_path}" "| "; then
|
if is_bin_present "${eza_user_path}" "| "; then
|
||||||
debug_message "Use Eza from user's path (${eza_user_path})"
|
### If EZA_OPTIONS is defined, call eza with options {{{
|
||||||
"${eza_user_path}" \
|
if [ -n "${EZA_OPTIONS-}" ]; then
|
||||||
|| error_message "Error while calling eza from user path (${eza_user_path})" 12
|
debug_message "Use Eza from user's path (${eza_user_path}) with options (${EZA_OPTIONS})."
|
||||||
|
"${eza_user_path}" $(echo "${EZA_OPTIONS}") \
|
||||||
|
|| error_message "Error while calling eza from system path (${eza_user_path})" 21
|
||||||
|
### }}}
|
||||||
|
### If EZA_OPTIONS is NOT defined simply call it {{{
|
||||||
|
elif [ -z "${EZA_OPTIONS-}" ]; then
|
||||||
|
debug_message "Use Eza from user's path (${eza_user_path}) without options."
|
||||||
|
"${eza_user_path}" \
|
||||||
|
|| error_message "Error while calling eza from user path (${eza_user_path})" 22
|
||||||
|
### }}}
|
||||||
|
### If anything else happens, exit with error {{{
|
||||||
|
else
|
||||||
|
error_message "This test case is not supposed to happen ! Variable EZA_OPTIONS is defined or not." 23
|
||||||
|
fi
|
||||||
|
### }}}
|
||||||
debug_message "--- MAIN END"
|
debug_message "--- MAIN END"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -184,8 +213,8 @@ if [ ! "${NBARGS}" -eq "0" ]; then
|
||||||
|
|
||||||
manage_arg="0"
|
manage_arg="0"
|
||||||
|
|
||||||
## If the first argument ask for help (h|help|-h|-help|-*h|-*help) {{{
|
## If the first argument ask for help (h|help) {{{
|
||||||
if printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^-*h(elp)?$"; then
|
if printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^h(elp)?$"; then
|
||||||
usage
|
usage
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -206,27 +235,26 @@ if [ ! "${NBARGS}" -eq "0" ]; then
|
||||||
while printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^-+"; do
|
while printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^-+"; do
|
||||||
|
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
-d|--debug ) ## debug
|
--debug ) ## debug
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
debug_message "--- Manage argument BEGIN"
|
debug_message "--- Manage argument BEGIN"
|
||||||
;;
|
;;
|
||||||
-u|--user ) ## Define eza_user_path with given arg
|
--user ) ## Define eza_user_path with given arg
|
||||||
## Move to the next argument
|
## Move to the next argument
|
||||||
shift
|
shift
|
||||||
## Define var
|
## Define var
|
||||||
readonly eza_user_path="${1}"
|
readonly eza_user_path="${1}"
|
||||||
;;
|
;;
|
||||||
-s|--system ) ## Define eza_system_path with given arg
|
--system ) ## Define eza_system_path with given arg
|
||||||
## Move to the next argument
|
## Move to the next argument
|
||||||
shift
|
shift
|
||||||
## Define var
|
## Define var
|
||||||
readonly eza_system_path="${1}"
|
readonly eza_system_path="${1}"
|
||||||
;;
|
;;
|
||||||
* ) ## unknow option
|
* ) ## unknow option
|
||||||
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
|
debug_message "Unknown option (${1}), pass it as eza's option"
|
||||||
printf '%b\n' "---"
|
test -n "${EZA_OPTIONS-}" && EZA_OPTIONS="${EZA_OPTIONS} ${1}"
|
||||||
usage
|
test -z "${EZA_OPTIONS-}" && EZA_OPTIONS="${1}"
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue