akinomyoga/ble.sh

[Bash ≤ 5.0, set -o vi] keybinding C-i (TAB) doesn't work (caused by 48c7bbe 2024-06-05)

Closed this issue · 17 comments

command "ble/widget/display-shell-version" or the result of pressing

GNU bash, version 4.4.20(1)-release (x86_64-redhat-linux-gnu) [Rocky Linux 8.10 (Green Obsidian)]
ble.sh, version 0.4.0-devel4+a9b962d (noarch) [git 2.43.5, GNU Make 4.2.1, GNU Awk 4.2.1, API: 2.0 (GNU MPFR 3.1.6-p2, GNU MP 6.1.2)]
bash-completion, version 2.7 (hash:d3d318284d3f9a575bd400fd38c8729e03b2fb16, 71791 bytes) (noarch)
fzf key-bindings, (hash:eae762f563e560bc0aa9adb5d7ef612b3b5c1b77, 151 bytes) (noarch)
WARNING: fzf integration "integration/fzf-key-bindings" is not activated.
fzf completion, (hash:eae762f563e560bc0aa9adb5d7ef612b3b5c1b77, 151 bytes) (noarch) (integration: on)
zoxide, version 0.9.4 (/home/$USER/.local/bin/zoxide)
atuin, version 18.3.0 (/home/$USER/.atuin/bin/atuin)
locale: LANG=en_US.utf8
terminal: TERM=xterm-256color wcwidth=10.0-west/15.1-2+ri, vte:5204 (1;5204;0)

I'm encountering an issue with autocompletion in my terminal. When I use the VMD program, autocompletion works fine for the first argument (e.g., protein.pdb), but it breaks when I try to autocomplete the second argument (e.g., md_all_protein_center.xtc). After this, normal typing becomes unresponsive—only the backspace and Ctrl + C keys function. Furthermore, autocompletion fails entirely if I attempt a new command after this, even for the first argument.

The only temporary fix I've found is to run the command complete -r, but I have to do this every time I open a new session. I've already tried removing the alias for vmd, but that didn't resolve the issue.

Is there a workaround or permanent fix for this behavior? I'd appreciate any guidance or suggestions. I'm happy to provide additional details if needed. Please let me know.

This is not specific to

My ~/.blerc

set -o vi 

ble-face auto_complete='fg=242,bg=235'
ble-face auto_complete='fg=white,bg=69'
ble-face auto_complete='fg=240,underline,italic'

# blerc

function my/complete-load-hook {
  bleopt complete_auto_complete=1
  bleopt complete_auto_wordbreaks=$' \t\n'
  bleopt complete_auto_history=
}

blehook/eval-after-load complete my/complete-load-hook

function blerc/vim-mode-hook {
  bleopt keymap_vi_mode_show=
  bleopt keymap_vi_mode_string_nmap=
  ble-bind -m vi_imap -f 'C-c' discard-line
  ble-bind -m vi_nmap -f 'C-c' discard-line
}
blehook/eval-after-load keymap_vi blerc/vim-mode-hook


I am happy to provide extra information if asked. Please let me know.

Thanks for the report. Although I'm not sure what is the VMD program, I guess it is related to the completion setting of the VMD command. ble.sh doesn't provide any completion setting, and the completion setting for the VMD command should be provided by another setting/framework.

  • Q1: What is the output of the following command?
$ complete -p vmd
  • Q2: If the result of the above command contains a part -F <funcname>, could you also provide the output of the following command (where <funcname> is replaced by the function name extracted by the Q1 command):
$ (shopt -s extdebug; declare -F '<funcname>')
  • Q3: You described that after attempting the completion of the second argument of vmd, the normal typing becomes unresponsive. Does that only happen after an attempt of the second argument of vmd? Or are there other commands that cause similar breakage?

  • Q4: What is VMD? Could you provide the official page or some documentation of the VMD program?

  • Q5: You provided your ~/.blerc. Does that mean the provided content of ~/.blerc is needed to reproduce the problem? Or does the problem reproduce with an empty ~/.blerc?

The output of complete -p vmd
bash: complete: vmd: no completion specification

The issue isn't limited to vmd; it also occurs with the cd command, even with the first argument. When using cd, the potential autocomplete options are displayed, but pressing Tab doesn't complete the text—only Ctrl + e works. However, running complete -r allows Tab to function as expected for autocompletion.

I've noticed that if I remove my ~/.blerc configuration file, the problem goes away, so it seems related to my configuration. My initial reason for setting up the configuration was to remove history from the autocomplete suggestions and to customize the background colors of the autocomplete menu.

VMD is Visual Molecular Dynamics, I think it has nothing to do with program (https://www.ks.uiuc.edu/Research/vmd/).

OK, then the completion setting for vmd is probably unrelated. What I suspect next is the fzf completion settings.

  • Q6: What is the output of the following command?
$ complete -p -D
  • Q7: How did you set up the fzf completion and fzf keybindings? Did you check README 2.8?
  • Q8: What are the outputs of the following commands?
$ (shopt -s extdebug; declare -F __fzf_orig_completion __fzf_select__)
$ declare -p __fzf_orig_completion __fzf_select__
$ type _fzf_complete __fzf_generic_path_completion

$ complete -p -D
complete -F _completion_loader -D

(shopt -s extdebug; declare -F __fzf_orig_completion __fzf_select__)
__fzf_orig_completion 212 /home/$USER/.fzf.bash
__fzf_select__ 35 /home/$USER/.fzf.bash
declare -p __fzf_orig_completion __fzf_select__
bash: declare: __fzf_orig_completion: not found
bash: declare: __fzf_select__: not found
type _fzf_complete __fzf_generic_path_completion
_fzf_complete is a function
_fzf_complete () 
{ 
    ble/function#advice/.proc "$FUNCNAME" "$@"
}
__fzf_generic_path_completion is a function
__fzf_generic_path_completion () 
{ 
    ble/function#advice/.proc "$FUNCNAME" "$@"
}

I configured fzf (now), by adding the line in the ~/.blerc source /etc/profile.d/bash_completion.sh and ble-import -d integration/fzf-completion

I think the issue is with setting up vi mode. When I comment out the set -o vi in ~/.blerc, I no longer have the issue. So, something is clashing with tab?

Also, I have bleopt complete_auto_history=, I still see some kind of prediction in autocompletion, any idea how to stop that?

I configured fzf (now), by adding the line in the ~/.blerc source /etc/profile.d/bash_completion.sh and ble-import -d integration/fzf-completion

Thanks. Then, I need to collect the information from the beginning with the new setup.

  • Q9(confirmation): Please make sure to deactivate the existing fzf settings (i.e., ~/.fzf.bash probably loaded from ~/.bashrc). If the fzf settings for ble.sh (i.e., ble-import -d integration/fzf-completion) and the existing fzf settings (in `~/.fzf.bash) are both enabled, they might interfere with each other.
  • Q9a: With the new setup, does the problem still reproduce?
  • Q9b: With the new setup, what are the outputs of the following commands?
$ (shopt -s extdebug; declare -F __fzf_orig_completion __fzf_select__)
$ type _fzf_complete __fzf_generic_path_completion

I think the issue is with setting up vi mode. When I comment out the set -o vi in ~/.blerc, I no longer have the issue.

I don't have an idea why that would affect the behavior. At least, the reported issue doesn't happen in my environment even if set -o vi is put in ~/.blerc. Also,

  • Q9c: Is this observation (for set -o vi in ~/.blerc) obtained after updating your fzf settings? Or was the observation with the older fzf settings? If that observation was obtained with the older fzf completion, what is the situation with the new setup? Does the problem reproduce with the new setup with and without set -o vi in your ~/.blerc?

So, something is clashing with tab?

As far as I can tell, the auto-complete feature is unrelated to tab. It doesn't use any tab bindings. But if you have a reason to suspect tab, could you describe it in a bit more detail?

Hmm, do you think the readline keybindings possibly interfere here?

  • Q10: What is the output of the following command after the problem reproduce in the session?
$ builtin bind -p

Also, I have bleopt complete_auto_history=, I still see some kind of prediction in autocompletion, any idea how to stop that?

bleopt complete_auto_history= just disables the completion source for auto-complete. To disable auto-complete, you need to use bleopt complete_auto_complete=. (This setting might probably hide the problem with auto-complete, but it doesn't mean that the original problem is fixed. To fix the problem, one needs to reproduce the problem, and to reproduce the problem, I think auto-complete needs to be turned on.)

Yes, I have the fzf settings in my .bashrc too. I commented them and sourced the .bashrc.
I have done the above with set -o vi enabled and I still have the issue.

With the updated settings, I commented out the vim mode enabling line, and I don't have the issue.

With the new setup, the outputs are

(shopt -s extdebug; declare -F __fzf_orig_completion __fzf_select__)
__fzf_orig_completion 57 /home/$USER/.fzf/shell/completion.bash
 type _fzf_complete __fzf_generic_path_completion
_fzf_complete is a function
_fzf_complete () 
{ 
    ble/function#advice/.proc "$FUNCNAME" "$@"
}
__fzf_generic_path_completion is a function
__fzf_generic_path_completion () 
{ 
    ble/function#advice/.proc "$FUNCNAME" "$@"
}

Explanation in detail:

Let's say I want to navigate to the Templates folder, so I type cd Te. I see a suggestion for Templates in gray. I expect pressing Tab to autocomplete the name, and pressing Enter should take me to that directory. However, in my case, while the suggestion appears in gray, pressing Tab doesn't complete the command. If I press Tab again, normal typing becomes unresponsive—only backspace and Ctrl + C work.

Is my understanding correct that the Tab should complete the autocompletion?

If I remove the 'set -o vi,` I get the expected behavior.

builtin bind -p output

# abort (not bound)
# accept-line (not bound)
# alias-expand-line (not bound)
# arrow-key-prefix (not bound)
# backward-byte (not bound)
# backward-char (not bound)
# backward-delete-char (not bound)
# backward-kill-line (not bound)
# backward-kill-word (not bound)
# backward-word (not bound)
# beginning-of-history (not bound)
# beginning-of-line (not bound)
# bracketed-paste-begin (not bound)
# call-last-kbd-macro (not bound)
# capitalize-word (not bound)
# character-search (not bound)
# character-search-backward (not bound)
# clear-screen (not bound)
"\C-i": complete
# complete-command (not bound)
# complete-filename (not bound)
# complete-hostname (not bound)
# complete-into-braces (not bound)
# complete-username (not bound)
# complete-variable (not bound)
# copy-backward-word (not bound)
# copy-forward-word (not bound)
# copy-region-as-kill (not bound)
# dabbrev-expand (not bound)
# delete-char (not bound)
# delete-char-or-list (not bound)
# delete-horizontal-space (not bound)
# digit-argument (not bound)
# display-shell-version (not bound)
# do-lowercase-version (not bound)
# downcase-word (not bound)
# dump-functions (not bound)
# dump-macros (not bound)
# dump-variables (not bound)
# dynamic-complete-history (not bound)
# edit-and-execute-command (not bound)
# emacs-editing-mode (not bound)
# end-kbd-macro (not bound)
# end-of-history (not bound)
# end-of-line (not bound)
# exchange-point-and-mark (not bound)
# forward-backward-delete-char (not bound)
# forward-byte (not bound)
# forward-char (not bound)
# forward-search-history (not bound)
# forward-word (not bound)
# glob-complete-word (not bound)
# glob-expand-word (not bound)
# glob-list-expansions (not bound)
# history-and-alias-expand-line (not bound)
# history-expand-line (not bound)
# history-search-backward (not bound)
# history-search-forward (not bound)
# history-substring-search-backward (not bound)
# history-substring-search-forward (not bound)
# insert-comment (not bound)
# insert-completions (not bound)
# insert-last-argument (not bound)
# kill-line (not bound)
# kill-region (not bound)
# kill-whole-line (not bound)
# kill-word (not bound)
# magic-space (not bound)
# menu-complete (not bound)
# menu-complete-backward (not bound)
# next-history (not bound)
# non-incremental-forward-search-history (not bound)
# non-incremental-forward-search-history-again (not bound)
# non-incremental-reverse-search-history (not bound)
# non-incremental-reverse-search-history-again (not bound)
# old-menu-complete (not bound)
# operate-and-get-next (not bound)
# overwrite-mode (not bound)
# possible-command-completions (not bound)
# possible-completions (not bound)
# possible-filename-completions (not bound)
# possible-hostname-completions (not bound)
# possible-username-completions (not bound)
# possible-variable-completions (not bound)
# previous-history (not bound)
# print-last-kbd-macro (not bound)
# quoted-insert (not bound)
# redraw-current-line (not bound)
# re-read-init-file (not bound)
# reverse-search-history (not bound)
# revert-line (not bound)
# self-insert (not bound)
# set-mark (not bound)
# shell-backward-kill-word (not bound)
# shell-backward-word (not bound)
# shell-expand-line (not bound)
# shell-forward-word (not bound)
# shell-kill-word (not bound)
# skip-csi-sequence (not bound)
# start-kbd-macro (not bound)
# tab-insert (not bound)
# tilde-expand (not bound)
# transpose-chars (not bound)
# transpose-words (not bound)
# tty-status (not bound)
# undo (not bound)
# universal-argument (not bound)
# unix-filename-rubout (not bound)
# unix-line-discard (not bound)
# unix-word-rubout (not bound)
# upcase-word (not bound)
# vi-append-eol (not bound)
# vi-append-mode (not bound)
# vi-arg-digit (not bound)
# vi-back-to-indent (not bound)
# vi-backward-bigword (not bound)
# vi-backward-word (not bound)
# vi-bword (not bound)
# vi-bWord (not bound)
# vi-change-case (not bound)
# vi-change-char (not bound)
# vi-change-to (not bound)
# vi-char-search (not bound)
# vi-column (not bound)
# vi-complete (not bound)
# vi-delete (not bound)
# vi-delete-to (not bound)
# vi-editing-mode (not bound)
# vi-end-bigword (not bound)
# vi-end-word (not bound)
# vi-eof-maybe (not bound)
# vi-eword (not bound)
# vi-eWord (not bound)
# vi-fetch-history (not bound)
# vi-first-print (not bound)
# vi-forward-bigword (not bound)
# vi-forward-word (not bound)
# vi-fword (not bound)
# vi-fWord (not bound)
# vi-goto-mark (not bound)
# vi-insert-beg (not bound)
# vi-insertion-mode (not bound)
# vi-match (not bound)
# vi-movement-mode (not bound)
# vi-next-word (not bound)
# vi-overstrike (not bound)
# vi-overstrike-delete (not bound)
# vi-prev-word (not bound)
# vi-put (not bound)
# vi-redo (not bound)
# vi-replace (not bound)
# vi-rubout (not bound)
# vi-search (not bound)
# vi-search-again (not bound)
# vi-set-mark (not bound)
# vi-subst (not bound)
# vi-tilde-expand (not bound)
# vi-unix-word-rubout (not bound)
# vi-yank-arg (not bound)
# vi-yank-pop (not bound)
# vi-yank-to (not bound)
# yank (not bound)
# yank-last-arg (not bound)
# yank-nth-arg (not bound)
# yank-pop (not bound)

Explanation in detail:

Let's say I want to navigate to the Templates folder, so I type cd Te. I see a suggestion for Templates in gray. I expect pressing Tab to autocomplete the name, and pressing Enter should take me to that directory. However, in my case, while the suggestion appears in gray, pressing Tab doesn't complete the command. If I press Tab again, normal typing becomes unresponsive—only backspace and Ctrl + C work.

Ah, OK. So auto-complete is actually unrelated. The auto-complete feature and the TAB completion are separate features. The completion performed by TAB is unrelated to auto-complete.

  • C-f, C-e, etc. are the keybindings to accept the suggestion by auto-complete.
  • TAB performs the completion independent of auto-complete, (though when you turn off the history auto-complete source by bleopt complete_auto_history=, the generated completions by the TAB completion would probably be consistent with auto-complete).

Is my understanding correct that the Tab should complete the autocompletion?

No, as described in detail above.

I've been thinking that the problem could be triggered by auto-complete, but I now confirmed that I can reproduce the problem by the TAB completion in my environment with Bash 4.4. The problem is unrelated to none of VMD, auto-complete, and fzf-completion, but is related to the TAB completion, set -o vi, and Bash 4.4.

builtin bind -p output

# abort (not bound)
[...]
# clear-screen (not bound)
"\C-i": complete
# complete-command (not bound)
[...]

OK, "\C-i": complete shouldn't appear. I recently updated the handling of this Readline binding for Bash 5.3-alpha in commit 48c7bbe. This commit seems to have introduced the problem in Bash <= 4.4 since I confirmed that the problem didn't arise before this commit.

Now that I could reproduce the problem in my environment and identify the cause, I can fix it on my side.

I pushed a fix 8e7ed82 to the master branch. @vasi786 Could you update ble.sh by running ble-update in a ble.sh session and check if the problem is fixed?

@akinomyoga Yep. It works perfectly now. Thank you for the quick fix.

Thank you!

Has anyone else noticed a performance issue after this update? My terminal has been hanging quite a bit lately. Sometimes, running even simple software, like gnuplot, takes up to a minute to show anything. It's not happening all the time, but when it does, it's really noticeable.

I'm using Zellij as a terminal multiplexer, and while opening a new pane happens quickly, the terminal itself often becomes unresponsive—or sometimes, nothing even displays at all. Is anyone else experiencing something similar?

Hmm, I don't experience it in my environment. I need more information.

Has anyone else noticed a performance issue after this update? My terminal has been hanging quite a bit lately. Sometimes, running even simple software, like gnuplot, takes up to a minute to show anything.

  • Does the problem happen with even simpler commands like echo or cd? Or does the command need to be some external commands?

I'm using Zellij as a terminal multiplexer, and while opening a new pane happens quickly, the terminal itself often becomes unresponsive—or sometimes, nothing even displays at all. Is anyone else experiencing something similar?

Is this a separate issue from the one in the previous paragraph?

  • Does this problem only happen in Zellij? How about the behavior in tmux and screen, or in new tabs of the outside terminal emulator?

I did some more testing and found the performance issue is unrelated to the update pushed, Instead related to the bash_completion.sh

I removed sourcing the 'bash_completion' before fzf_completion (in .blerc), and my terminal responds and speeds up much better.

With sourcing the bash_completion, the terminal will be responsive initially, but it lags if I keep working (opening new tabs or doing standard stuff).

This is the line I removed source /etc/profile.d/bash_completion.sh

Ah, OK. Thank you for the information. Then, some of the completion functions provided by bash-completion can be slow.

This is one of the subtle compatibility issues about the completion settings. The bash-completion project provides the completion settings primarily intended to be used with the plain Bash (but not with ble.sh), and it intends to offer completions for the TAB completion. However, ble.sh wants to use the same completion settings for auto-complete (i.e., the completion feature performed in the background and showing the suggestions). Some heavy completions may be acceptable for the TAB completion (where the user explicitly requests the completion by hitting TAB) but can be unacceptable for auto-complete (which would be automatically triggered in the background), (though one minute seems unacceptable for both of the TAB and auto-completions).

This is the line I removed source /etc/profile.d/bash_completion.sh

If you want to disable those slow completions for both the TAB and auto-completions, that is fine.

Another option might to be to enable the completion settings only for the TAB completion by disabling it for auto-complete. You can disable auto-complete based on the completion settings (including the ones provided by bash-completion) by the following setting:

# ~/.blerc

ble-import core-complete -C 'ble/array#remove _ble_complete_auto_source syntax'

Thank you for the info.