chrisant996 / clink

Bash's powerful command line editing in cmd.exe
https://chrisant996.github.io/clink/
GNU General Public License v3.0
3.54k stars 140 forks source link

Can I keep completion style both bash and windows? #245

Closed 836454543 closed 2 years ago

836454543 commented 2 years ago

Hi, I'm confused about it now. Although I used to bash style, I sometimes want to use windows style completion. I try to do this clink set clink.default_bindings bash set .inputrc file "\eq": old-menu-complete and "\eQ": old-menu-complete-backward old-menu-complete will show possible completion, which I don't want. How can I make alt+q just like windows style completion?

chrisant996 commented 2 years ago

Maybe you are trying to find the Init File and New Commands sections in the documentation? Maybe you are looking for the clink-select-complete command?

If those aren't what you're looking for, then please describe what you mean by "windows style completion". What do you want to happen? What do you mean by "old-menu-complete will show possible completion, which I don't want"? (I would have described old-menu-complete as the closest thing to "Windows style completion", since it behaves exactly like Tab in cmd.exe without Clink.)

836454543 commented 2 years ago

I'm sorry for my poor description. old-menu-complete complete like Windows style, but it will list all possible completions above the current line just like Bash style. The cmd.exe just complete word, it will not display all possible completions above the current line. That is what I want.

chrisant996 commented 2 years ago

I think you are saying:

I'm not sure if I understand accurately, though.

I think you are looking for the clink-select-complete command, as I mentioned earlier. Have you tried that?

Is this what you want? image

836454543 commented 2 years ago

You want Tab to do bash-like completion (the complete command).---------------------Yes Yes Yes You want Alt+Q to do a different kind of completion------------------------------Yes Yes Yes

chrisant996 commented 2 years ago
  • You want it to list all possible completions.-----------------------------------NO NO NO! I don't need it, but old-menu-complete do this.

No, old-menu-complete never lists anything. It is the same as Tab in plain cmd.exe without Clink.

  • with the next option from the list of possible completions.------------------------NO NO NO!!!!!

That sounds like it contradicts the previous statement. Here is an animated GIF file of how old-menu-complete works: old-menu-complete

Can you paste your entire .inputrc file here? Maybe there is something else later in the file that's interfering?

836454543 commented 2 years ago

My .inputrc file

set completion-ignore-case on
set show-all-if-ambiguous on
set colored-completion-prefix on
set colored-stats on
set bell-style none
set editing-mode emacs

# ↑
"\e[A": history-search-backward
# ↓
"\e[B": history-search-forward
# alt + z
"\ez": undo
# alt + q
"\eq": old-menu-complete
# alt + Q
"\eQ": old-menu-complete-backward
"\t": complete
# ctrl + l,清除一整行内容
"\C-l": kill-whole-line

$if bash
    # cmd风格的操作
    # ctrl + ←
    "\e[1;5D": backward-word
    # ctrl + →
    "\e[1;5C": forward-word
    # Cmder中的alt + del
    "\e[3;3~": backward-kill-word
    # MobaXterm中的alt + del
    "\e\e[3~": backward-kill-word
    # ctrl + home
    "\e[1;5H": unix-line-discard
    # ctrl + end
    "\e[1;5F": kill-line
$endif

$if clink
    # 每次查询历史指令时,光标跳到指令的最末尾
    set history-point-at-end-of-anchored-search on
    # 跳转到父目录
    "\ep": clink-up-directory
    # ctrl + space选择补全
    "\e[27;5;32~": clink-select-complete 
    "\C-z": undo
    "\C-y": redo
    "\C-a": beginning-of-line
    "\C-e": end-of-line
    # alt + `设为文本%USERPROFILE%的快捷键,方便输入
    "\e`": "%USERPROFILE%"
$endif

My clink set: QQ图片20220226122850 QQ图片20220226123038

a

chrisant996 commented 2 years ago

Using the .inputrc file you shared, I can reproduce the problem.

The cause is this line:

set show-all-if-ambiguous on

The purpose of that Readline option is to always list all the matches if there is more than one match. See Init File Syntax in the Readline manual.

Removing that line will make Alt+q behave as desired. I imagine you have the line there because you want the complete command to always immediately list matches. Readline doesn't seem to have a way to simultaneously configure the two commands to each work how you prefer.

You might try this line instead, though:

set completion-query-items -1

(I agree that it seems like strange behavior in Readline. And the menu-complete behavior makes even less sense when show-all-if-ambiguous is on -- if you haven't typed anything yet and invoke menu-complete then it only lists all and never cycles through completions at all. You might want to report these issues to the bash and Readline maintainers -- these issues will occur in bash as well. But, based on code here and here, it looks like these are both very intentional behaviors.)