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 <joe.macdonald@siemens.com>
This commit is contained in:
Joe MacDonald
2023-02-23 10:06:09 -05:00
committed by GitHub
parent 8531e1ba3c
commit 3a26319b9e

View File

@@ -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.