git completion error in bash
阿神
阿神 2017-05-02 09:28:05
0
2
633

在新安装的Debian的Bash下,通过sudo apt-get install git安装后,git的补全出现异常。

$ git  ^[[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

部分是正常的,比如git revert。但是很大一部分,比如git add,由于补全项为git a^[[m^[[Kdd而无法正常使用。

请问:

  1. Bash中,这个^[[m^[[K是什么?

  2. 如何去除它,让git的补全正常?

(我曾经用过git-completion这个方案,但是它太老,早已不更新,导致新功能补全缺失。)

阿神
阿神

闭关修行中......

reply all (2)
Ty80

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:

  1. Turn off the coloring of Git completions

  2. Adjust your terminal to support ANSI Escape Code

If your Terminal Emulator supports color, changing it$TERMcan 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

    Bash, what is this^[[m^[[K?

    is ANSI escape code.^[represents theESCkey, and^[[isESC[represents CSI (Control Sequence Introducer), so^[表示ESC键,而^[[ESC[表示 CSI(Control Sequence Introducer),所以^[[m^[[Kmeans 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 CSInm,表示 SGR – Select Graphic Rendition,即控制台中的文本的渲染效果。其中n是0至多个参数,当没有参数的时候就成了 CSI m,表示重置为默认渲染效果。具体见这里。(自定义控制台的 PS 也是通过这个来设置颜色的。) 例如,问题开头的^[[1;43mwhich stands for "bold;red" rendering effect.

    The full form of

    CSI K is when CSInK,表示 EL – Erase in Line,即删除部分行。其中n也是参数,当nis 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.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!