Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(_comp_expand_glob): set LC_COLLATE for the sorting order
In sourcing the file `000_bash_completion_compat.bash` located in /etc/bash_completion.d, we rely on the sorting order of the pathname expansions. However, this can be broken by locales that collates digits after the alphabets. We set LC_COLLATE to C and unset LC_ALL (which might override LC_COLLATE) while keeping LC_CTYPE.
- Loading branch information
ce98f68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That effects in error:
-bash: warning: setlocale: LC_COLLATE: cannot change locale (): No such file or directory
-bash: warning: setlocale: LC_COLLATE: cannot change locale (): No such file or directory
ce98f68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you see the error message, it implies the locale setup in the system is broken. What are the results of the following commands in your environment?
ce98f68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put:
export LANG="en_GB.UTF-8"
export LC_ALL="en_GB.UTF-8"
in .bash_profile and the problem vanished?
I didn't have any LC_x nor LANG wherever.
I'm doing that on macOS X.
Shouldn't LANG be ${LANG:-} instead of ${LANG-} in this line btw?
ce98f68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With an empty default value, the colon does not make a difference. We leave it out as a matter of style.
ce98f68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, setting
LANG
to one that exists in the system is recommended.However, you shouldn't globally set
LC_ALL
, actually. The environment variableLC_ALL
is used to temporarily force the locale to a specified one for a specific purpose. It disables all the otherLANG
andLC_*
variables, which would cause problems. In the above code inbash-completion
, we carefully temporarily unsetLC_ALL
in case a user wrongly setLC_ALL
globally, but not all the locale-dependent applications carefully handle the unexpected globalLC_ALL
.