From 3a26319b9e00c4f1de636a62f0f7fa155063962f Mon Sep 17 00:00:00 2001 From: Joe MacDonald Date: Thu, 23 Feb 2023 10:06:09 -0500 Subject: [PATCH] lib/shopt: tweak OMB_CASE_SENSITIVE handling in shopt (#399) The CASE_SENSITIVE setting is checked when setting case-insensitive globbing but not matching (for features such as command / programmable completion). Add checks in the appropriate places, preserving the default (insensitive) behaviour unless explicitly changed. This will allow case-sensitivity to apply in an intuitive way, treating paths, filename completions and command completions consistently. Signed-off-by: Joe MacDonald --- lib/shopt.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/shopt.sh b/lib/shopt.sh index 6f677fb..9e5f887 100644 --- a/lib/shopt.sh +++ b/lib/shopt.sh @@ -19,18 +19,26 @@ PROMPT_DIRTRIM=2 bind Space:magic-space # Turn on recursive globbing (enables ** to recurse all directories) -shopt -s globstar 2> /dev/null +shopt -s globstar 2> /dev/null -# Case-insensitive globbing (used in pathname expansion) -shopt -s nocaseglob; +# Case-sensitive globbing (used in pathname expansion) and matching +# (used in case, [[]], word expansions and command completions) +if [[ ${OMB_CASE_SENSITIVE:-${CASE_SENSITIVE:-}} == true ]]; then + shopt -u nocaseglob + shopt -u nocasematch +else + shopt -s nocaseglob + shopt -s nocasematch +fi ## SMARTER TAB-COMPLETION (Readline bindings) ## -# Perform file completion in a case insensitive fashion +# Conditionally perform file completion in a case insensitive fashion. +# Setting OMB_CASE_SENSITIVE to 'true' will switch from the default, +# case insensitive, matching to the case-sensitive one +# # Note: CASE_SENSITIVE is the compatibility name -if [[ ${OMB_CASE_SENSITIVE:-${CASE_SENSITIVE:-}} == false ]]; then - bind "set completion-ignore-case on" -elif [[ ${OMB_CASE_SENSITIVE:-${CASE_SENSITIVE:-}} == true ]]; then +if [[ ${OMB_CASE_SENSITIVE:-${CASE_SENSITIVE:-}} == true ]]; then bind "set completion-ignore-case off" else # By default, case sensitivity is disabled.