Under the newly installed Debian Bash, after installing through sudo apt-get install git
, the completion of git appears abnormally.
$ git <TAB>
^[[1;43m^[[K c^[[m^[[Kherry d^[[m^[[Kifftool h^[[m^[[Kttp-backend m^[[m^[[Kerge-file rm
a^[[m^[[Kdd c^[[m^[[Kherry-pick d^[[m^[[Kiff-tree h^[[m^[[Kttp-fetch m^[[m^[[Kerge-index shortlog
a^[[m^[[Km c^[[m^[[Klean f^[[m^[[Kast-export h^[[m^[[Kttp-push m^[[m^[[Kerge-octopus show
a^[[m^[[Knnotate c^[[m^[[Klone f^[[m^[[Kast-import i^[[m^[[Kmap-send mv show-branch
a^[[m^[[Kpply c^[[m^[[Kolumn f^[[m^[[Ketch i^[[m^[[Kndex-pack name-rev stage
a^[[m^[[Krchive c^[[m^[[Kommit f^[[m^[[Ketch-pack i^[[m^[[Knit notes stash
b^[[m^[[Kisect c^[[m^[[Kommit-tree f^[[m^[[Kilter-branch i^[[m^[[Knit-db pull status
b^[[m^[[Klame c^[[m^[[Konfig f^[[m^[[Kmt-merge-msg i^[[m^[[Knstaweb push submodule
b^[[m^[[Kranch c^[[m^[[Kount-objects f^[[m^[[Kor-each-ref l^[[m^[[Kog rebase subtree
b^[[m^[[Kundle c^[[m^[[Kredential f^[[m^[[Kormat-patch l^[[m^[[Ks-files reflog tag
c^[[m^[[Kat-file c^[[m^[[Kredential-cache f^[[m^[[Ksck l^[[m^[[Ks-remote relink verify-commit
c^[[m^[[Kheck-attr c^[[m^[[Kredential-store f^[[m^[[Ksck-objects l^[[m^[[Ks-tree remote whatchanged
c^[[m^[[Kheck-ignore d^[[m^[[Kaemon g^[[m^[[Kc mergetool repack
c^[[m^[[Kheck-mailmap d^[[m^[[Kescribe g^[[m^[[Ket-tar-commit-id m^[[m^[[Kailinfo replace
c^[[m^[[Kheckout d^[[m^[[Kiff g^[[m^[[Krep m^[[m^[[Kailsplit request-pull
c^[[m^[[Kheckout-index d^[[m^[[Kiff-files h^[[m^[[Kash-object m^[[m^[[Kerge reset
c^[[m^[[Kheck-ref-format d^[[m^[[Kiff-index h^[[m^[[Kelp m^[[m^[[Kerge-base revert
The part is normal, such as git revert
. But a large part, such as git add
, cannot be used normally because the completion item is git a^[[m^[[Kdd
.
Excuse me:
What is this ^[[m^[[K
in Bash?
so that the completion of git
works normally?
(I once used the git-completion solution, but it is too old and has not been updated, resulting in the lack of new feature completion.)
I emphasize again, a terminal is a terminal, and a Shell is a Shell. There are always people who can’t tell the difference between a terminal and a Shell...
This problem is caused by improper configuration of your terminal. No matter how powerful Bash is, it cannot handle the analysis of ANSI Escape Code. Just like you can't make a black and white monitor display colors if you replace an i3 with an i7.
You have two options:
Turn off the coloring of Git completions
Adjust your terminal to support ANSI Escape Code
If your Terminal Emulator supports color, changing it
$TERM
can usually solve the problem. For more detailed instructions, please refer to http://www.tldp.org/HOWTO/Text-Terminal-HOWTO-16.html and the links on this page.In
is ANSI escape code.
^[
represents the ESC key, and^[[
is ESC[
represents CSI (Control Sequence Introducer), so^[
表示ESC键,而^[[
即ESC[
表示 CSI(Control Sequence Introducer),所以^[[m^[[K
means CSI m, CSI K. As for what CSI m and CSI K mean, you need to look up the table.The full form of CSI m is CSI
The full form ofn
m,表示 SGR – Select Graphic Rendition,即控制台中的文本的渲染效果。其中n
是0至多个参数,当没有参数的时候就成了 CSI m,表示重置为默认渲染效果。具体见这里。(自定义控制台的 PS 也是通过这个来设置颜色的。) 例如,问题开头的^[[1;43m
which stands for "bold;red" rendering effect.CSI K is when CSI
n
K,表示 EL – Erase in Line,即删除部分行。其中n
也是参数,当n
is 0 or omitted, that is, CSI K, which means deleting from the cursor position to the end of the line. For other situations, please refer to the description in Wikipedia.