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() { # {{{
|
||||
|
||||
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)
|
||||
|
||||
@ -55,22 +55,24 @@ EXAMPLES :
|
||||
${PROGNAME}
|
||||
|
||||
- Set different binary for user
|
||||
${PROGNAME} -u "${HOME}/bin/my.eza"
|
||||
${PROGNAME} --user "${HOME}/bin/my.eza"
|
||||
|
||||
OPTIONS :
|
||||
-d,--debug
|
||||
--debug
|
||||
Enable debug messages.
|
||||
|
||||
-h,--help
|
||||
help
|
||||
Print this help message.
|
||||
|
||||
-u,--user
|
||||
--user
|
||||
Change the user's binary to use.
|
||||
(default: ${EZA_USER_PATH})
|
||||
|
||||
-s,--system
|
||||
--system
|
||||
Change the system's binary to use.
|
||||
(default: ${EZA_SYSTEM_PATH})
|
||||
|
||||
ALL OTHER OPTIONS WILL BE PASSED AS EZA's OPTIONS
|
||||
HELP
|
||||
}
|
||||
# }}}
|
||||
@ -155,19 +157,46 @@ main() { # {{{
|
||||
## If eza system is available {{{
|
||||
### Start it
|
||||
if is_bin_present "${eza_system_path}" "| "; then
|
||||
debug_message "Use Eza from system (${eza_system_path})"
|
||||
"${eza_system_path}" \
|
||||
|| error_message "Error while calling eza from system path (${eza_system_path})" 11
|
||||
### If EZA_OPTIONS is defined, call eza with options {{{
|
||||
if [ -n "${EZA_OPTIONS-}" ]; then
|
||||
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"
|
||||
exit 0
|
||||
fi
|
||||
## }}}
|
||||
## If eza from user path is available {{{
|
||||
### Start it
|
||||
if is_bin_present "${eza_user_path}" "| "; then
|
||||
debug_message "Use Eza from user's path (${eza_user_path})"
|
||||
"${eza_user_path}" \
|
||||
|| error_message "Error while calling eza from user path (${eza_user_path})" 12
|
||||
### If EZA_OPTIONS is defined, call eza with options {{{
|
||||
if [ -n "${EZA_OPTIONS-}" ]; then
|
||||
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"
|
||||
exit 0
|
||||
fi
|
||||
@ -184,8 +213,8 @@ if [ ! "${NBARGS}" -eq "0" ]; then
|
||||
|
||||
manage_arg="0"
|
||||
|
||||
## If the first argument ask for help (h|help|-h|-help|-*h|-*help) {{{
|
||||
if printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^-*h(elp)?$"; then
|
||||
## If the first argument ask for help (h|help) {{{
|
||||
if printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^h(elp)?$"; then
|
||||
usage
|
||||
exit 0
|
||||
fi
|
||||
@ -206,27 +235,26 @@ if [ ! "${NBARGS}" -eq "0" ]; then
|
||||
while printf -- '%s' "${1-}" | grep --quiet --extended-regexp -- "^-+"; do
|
||||
|
||||
case "${1}" in
|
||||
-d|--debug ) ## debug
|
||||
--debug ) ## debug
|
||||
DEBUG=0
|
||||
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
|
||||
shift
|
||||
## Define var
|
||||
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
|
||||
shift
|
||||
## Define var
|
||||
readonly eza_system_path="${1}"
|
||||
;;
|
||||
* ) ## unknow option
|
||||
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
|
||||
printf '%b\n' "---"
|
||||
usage
|
||||
exit 1
|
||||
debug_message "Unknown option (${1}), pass it as eza's option"
|
||||
test -n "${EZA_OPTIONS-}" && EZA_OPTIONS="${EZA_OPTIONS} ${1}"
|
||||
test -z "${EZA_OPTIONS-}" && EZA_OPTIONS="${1}"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user