Bash-completion is very slow on MSYS2 (original) (raw)
Bash-completion is very slow on MSYS2 when the current user is a domain user. This describes the cause and the solutions.
Cause
Expansion of ~*
is very slow when you use a domain user. For example:
$ time echo ~*
~*
real 0m23.151s
user 0m0.000s
sys 0m0.000s
When the tab key is pressed, bash-completion tries to evaluate ~*
. That's why bash-completion is slow.
Solution 1: Disable ~*
in bash_completion
~*
is used inside /usr/share/bash-completion/bash_completion
. Disabling it can solve the problem.
--- /usr/share/bash-completion/bash_completion.org +++ /usr/share/bash-completion/bash_completion @@ -542,9 +542,9 @@ elif [[ $1 == '* ]]; then # Leave out first character printf -v 22 %s "2{1:1}"
- elif [[ $1 == ~* ]]; then
# avoid escaping first ~
printf -v <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>2</mn><mtext> </mtext></mrow><annotation encoding="application/x-tex">2 ~%q "</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">2</span><span class="mspace nobreak"> </span></span></span></span>{1:1}"
- #elif [[ $1 == ~* ]]; then
# avoid escaping first ~
2 2 ~%q "2 {1:1}"
else printf -v printf -v 22 %q "21" fi
Solution 2: Disable db
in /etc/nsswitch.conf
MSYS2 obtains the user information from the system database (in Windows) by default, but it is very slow when the current user is a domain user. Disabling it and make MSYS2 to obtain the user information from files solves the problem.
First you need to create /etc/passwd
and /etc/group
with the information of the local users (-l
) and the current (domain) user (-c
).
$ mkpasswd -l -c > /etc/passwd $ mkgroup -l -c > /etc/group
Then you need to modify /etc/nsswitch.conf
to disable db
from group
andpasswd
.
--- /etc/nsswitch.conf.org +++ /etc/nsswitch.conf @@ -1,7 +1,7 @@
Begin /etc/nsswitch.conf
-passwd: files db -group: files db +passwd: files #db +group: files #db
db_enum: cache builtin
If you don't update /etc/passwd
and /etc/group
properly, bash prompt might show your account as Unknown+User
.
See also:
man 5 nsswitch.conf
on Linux- msys2/MSYS2-packages#138 (comment)