complete-alias
complete-alias copied to clipboard
possible conflicts with fzf
Hi,
This is a follow-up to #40. I'm opening a new issue because the older one has been closed and i've been able to come up with a reproducer.
How to reproduce
Build the following docker file docker build -t compal:gh46 .
Dockerfile
# syntax=docker/dockerfile:1.4
FROM debian:bookworm-slim
RUN <<EOS
set -ex
apt update && apt install -y --no-install-recommends \
bash-completion \
ca-certificates \
curl \
git
adduser test
EOS
USER test
WORKDIR /home/test
RUN bash <<'EOS'
set -ex
git clone --depth=1 https://github.com/cykerway/complete-alias.git compal
git clone --depth=1 https://github.com/junegunn/fzf.git .fzf
./.fzf/install
EOS
COPY <<'EOF' ./.bash_aliases
alias ls="ls --color=auto"
EOF
COPY <<'EOF' ./.bash_completion
source ~/compal/complete_alias
complete -F _complete_alias "${!BASH_ALIASES[@]}"
EOF
Run a bash session in a container:
docker run -it --rm compal:gh46 bash
On the bash prompt, type ls -<TAB>
.
The shell enters an infinite loop, reapetedly outputing error: cannot unmask alias command: ls
.
Type <Ctrl-C>
until you can go back to the prompt and exit.
How to fix
Running docker run -it --rm compal:gh46 tail .bashrc
outputs:
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
We can see that the fzf
installation script has blindly appended it's source command. The result is that the fzf completion script is sourced after ~./bash_completion
(since the latter is itself sourced at the end of /usr/share/bash-completion/bash_completion
).
If we instead use the following dockerfile:
Dockerfile
# syntax=docker/dockerfile:1.4
FROM debian:bookworm-slim
RUN <<EOS
set -ex
apt update && apt install -y --no-install-recommends \
bash-completion \
ca-certificates \
curl \
git
adduser test
EOS
USER test
WORKDIR /home/test
RUN bash <<'EOS'
set -ex
git clone --depth=1 https://github.com/cykerway/complete-alias.git compal
git clone --depth=1 https://github.com/junegunn/fzf.git .fzf
./.fzf/install --no-update-rc
EOS
COPY <<'EOF' ./.bash_aliases
alias ls="ls --color=auto"
EOF
COPY <<'EOF' ./.bash_completion
source ~/.fzf.bash
source ~/compal/complete_alias
complete -F _complete_alias "${!BASH_ALIASES[@]}"
EOF
Then typing ls -<TAB><TAB><TAB>
correctly shows the ls option completions, but typing ls /etc/**<TAB>
does not show the fzf path completions.
If we now export COMPAL_AUTO_UNMASK=1
at the top of ~/.bash_completion
, then typing ls -<TAB><TAB><TAB>
correctly shows the ls option completions, and typing ls /etc/**<TAB>
correctly shows the fzf path completions.
Final notes
I do not have the knowledge required to find tha actual cause of the issue, nor to tell if it's a bug in complete-alias
, fzf
, bash
itself or just a fundamental limitation of the bash completion system...
However I think that this might warrant an entry in the docs stating that care should be taken that, in presence of other completion handlers, complete_alias
should be sourced last, and that the COMPAL_AUTO_UNMASK
setting may resolve some conflicts.