akinomyoga / ble.sh

Bash Line Editor―a line editor written in pure Bash with syntax highlighting, auto suggestions, vim modes, etc. for Bash interactive sessions.
BSD 3-Clause "New" or "Revised" License
2.69k stars 85 forks source link

[fzf, bash-completion] completion for "ls" and others do not add "/" after completing a directory name when using "~" at the beginning #264

Closed qoreQyaS closed 1 year ago

qoreQyaS commented 1 year ago

ble version: 0.4.0-devel3+fb7bd0b

Bash version: 5.2.2(1)-release (x86_64-pc-linux-gnu)

GNU bash, version 5.2.2(1)-release (x86_64-pc-linux-gnu) [Debian GNU/Linux bookworm/sid]
ble.sh, version 0.4.0-devel3+fb7bd0b (noarch) [git 2.38.1, GNU Make 4.3, GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.1.0, GNU MP 6.2.1)]
bash-completion, version 2.11 (hash:aefcfdd4b924e8b03db0d49be8bdb5881ad7d0cd, 77084 bytes) (noarch)
fzf key-bindings, version +18e3b38c (noarch) (integration: on)
fzf completion, version +18e3b38c (noarch) (integration: on)
locale: LANG=en_US.UTF-8 LC_MONETARY=de_DE.UTF-8 LC_PAPER=de_DE.UTF-8 LC_TIME=de_DE.UTF-8
terminal: TERM=tmux-256color wcwidth=14.0-west/15.0-2+ri, tmux:0 (84;0;0)
bashrc & blerc ## ~/.bashrc `grep -v '^[ \t]*#' ~/.bashrc|awk NF` ```bash case $- in *i*) ;; *) return;; esac if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias ls='ls --color=auto' alias dir='dir --color=auto' alias vdir='vdir --color=auto' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' fi source /home/sgrewe/.local/share/blesh/ble.sh --noattach function _update_ps1() { PS1=$(powerline-shell $?) } if [[ $TERM != linux && ! $PROMPT_COMMAND =~ _update_ps1 ]]; then PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND" fi HISTSIZE=100000 HISTTIMEFORMAT="%F %T " HISTCONTROL=ignoredups:erasedups:ignorespace shopt -s histappend shopt -s cmdhist lithist shopt -s checkwinsize shopt -s globstar if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi . "$HOME/.cargo/env" set -a source /etc/environment for i in /etc/environment.d/*.conf; do source "${i}" done export RIPGREP_CONFIG_PATH=/home/sgrewe/.config/ripgrep/rg.conf set +a export FD_OPTIONS="--hidden --follow" export FZF_DEFAULT_OPTS="--bind \"F1:toggle-preview\" --no-mouse --height 80% --reverse --multi --info=inline --preview \"rougify {} 2> /dev/null || cat {} 2> /dev/null || tree -C {} 2> /dev/null | head -100\" --color dark,hl:33,hl+:37,fg+:235,bg+:136,fg+:254 --color info:254,prompt:37,spinner:108,pointer:235,marker:235" export FZF_DEFAULT_COMMAND="git ls-files --cached --others --exclude-standard 2>/dev/null || fdfind --type f --type l $FD_OPTIONS" export FZF_CTRL_R_OPTS="--bind \"F1:toggle-preview\" --preview \"echo {}\" --preview-window down:3:hidden:wrap" export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" export PATH="${HOME}/bin:${HOME}/.local/bin:${PATH}:${HOME}/.local/share/gem/ruby/3.1.0/bin" [[ ${BLE_VERSION-} ]] && ble-attach ble-bind -f up 'history-search-backward immediate-accept' ble-bind -f down 'history-search-forward immediate-accept' _ble_contrib_fzf_base=$HOME/.fzf ble-import -d contrib/fzf-completion ble-import -d contrib/fzf-key-bindings ``` ## ~/.blerc `grep -v '^[ \t]*#' ~/.blerc|awk NF` ```bash bleopt history_lazyload=1 bleopt history_share=on bleopt history_erasedups_limit= # entire history bleopt complete_auto_complete=1 bleopt complete_menu_complete=1 bleopt complete_menu_filter=1 bleopt complete_contract_function_names=1 bleopt complete_auto_history=1 bleopt complete_auto_delay=1000 bleopt complete_auto_menu=2000 bleopt complete_menu_color=on bleopt filename_ls_colors="$LS_COLORS" bleopt highlight_syntax=true bleopt highlight_filename=true bleopt highlight_variable=true function blerc/emacs-load-hook { return } blehook/eval-after-load keymap_emacs blerc/emacs-load-hook function blerc/vim-load-hook { ((_ble_bash>=40300)) && builtin bind 'set keyseq-timeout 1' } blehook/eval-after-load keymap_vi blerc/vim-load-hook ```

Hi,

certain completions don't add a / after the directory name when using ~ in the beginning of the path, no matter how often i press TAB. When waiting for autocomplete only the directory without / in the end is offered.

examples for not working completions:

image

ls

complete -p ls
complete -F _fzf_path_completion ls

cat

complete -p cat
complete -F _fzf_path_completion cat

view

complete -p view
complete -o bashdefault -o default -F _fzf_path_completion view

examples for working completions

image

echo

complete -p echo
-bash: complete: echo: no completion specification
[ble: exit 1]

dir

complete -p dir
complete -F _longopt dir

ssh

complete -p ssh
complete -o bashdefault -o default -F _fzf_host_completion ssh

any non existent keyword also works and has no completion defined for example wurst

complete -p wurst
-bash: complete: wurst: no completion specification
akinomyoga commented 1 year ago

Thank you for the detailed report. I could reproduce the problem, so I fixed it at my side. I pushed a fix 32277dae20f004c3a65aeb3adae881b8b8e0318f to the master. Could you update ble.sh by ble-update and check if it is now working as expected?

[ Summary of the issue: This was caused by a design conflict with fzf. Most programmable completion settings do not correctly handle various quotes, the tilde expansion, and the pathname expansions, so ble.sh adjusts the programmable completion so that completers do not have to handle these non-trivial transformations. However, ble.sh needs to turn off these adjustments for fzf because fzf tries to find a special meaning on a particular combination of pathname expansions ** unlike the other completions. This exceptional treatment for fzf was already implemented. Here, the problem was that some part of the handlers in ble.sh assumed the adjustments. In particular, when fzf was combined with bash-completion, the issue arises. I now implemented the treatment for the case where the adjustments are turned off. ]

qoreQyaS commented 1 year ago

it is also working on my side. thank you very much for the extensive elucidation and the clearance of the stain in your great addition to bash.

akinomyoga commented 1 year ago

Thank you!