szermatt / emacs-bash-completion

Add programmable bash completion to Emacs shell-mode
GNU General Public License v2.0
281 stars 33 forks source link

Failure to Complete #71

Closed phikal closed 4 months ago

phikal commented 5 months ago

Hi, I was trying to complete a directory path ~/Doc to ~/Documents using M-x shell, but instead I got this error message:

commandline: <<EOF
__emacs_complete_pre_command; function __emacs_complete_pre_command {  if [[ -z "$__emacs_complete_ps1" ]]; then    __emacs_complete_ps1="$PS1";    __emacs_complete_pc="$PROMPT_COMMAND";  fi;  PROMPT_COMMAND=__emacs_complete_prompt;  if [[ ${BASH_VERSINFO[0]} -eq 5 && ${BASH_VERSINFO[1]} -ge 1 || ${BASH_VERSINFO[0]} -gt 5 ]]; then  history -d $HISTCMD &>/dev/null || true;else  history -d $((HISTCMD - 1)) &>/dev/null || true;fi;} &&function __emacs_complete_prompt {  PS1='    $?';  PROMPT_COMMAND=__emacs_complete_recover_prompt;} &&function __emacs_complete_recover_prompt {  local r=$?;  PS1="${__emacs_complete_ps1}";  PROMPT_COMMAND="${__emacs_complete_pc}";  unset __emacs_complete_ps1 __emacs_complete_pc;  if [[ -n "$PROMPT_COMMAND" ]]; then    (exit $r); eval "$PROMPT_COMMAND";  fi;} &&__emacs_complete_pre_command
EOF

error: "timeout"

buffer-string: <<EOF
bash: __emacs_complete_pre_command: command not found...
EOF

process: #<process shell>

output-buffer: <<EOF
bash: __emacs_complete_pre_command: command not found...
    0EOF

emacs-version: "30.0.50"

I have had a similar issue from time to time, but haven't been able to identify what the root cause is. Does the above give any hints? My Bash version is

$ bash --version
GNU bash, version 5.2.26(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
jessie-hu-95 commented 5 months ago

I have similar issue when I connect through TRAMP. I have a customized prompt.

phikal commented 4 months ago

My prompt is just a dollar sign, and this occurs locally. That being said, I do notice that the issue appears to disappear when I rename my .bashrc to something else, which Bash won't load.

After experimenting a bit, I pulled out this block from by .bashrc:

if [ -f /etc/bashrc ]
then
    . /etc/bashrc
fi

and added that to my .bash_profile. This had the same effect as disabling .bashrc, but now my regular terminal didn't do any completion. This could be fixed by enabling the "Run command as login shell" option, in GNOME terminal.

szermatt commented 4 months ago

Sorry for the long silence! I hadn't noticed this issue.

This issue could be caused by a lot of things, such as some version incompatibility or some option turned on in your .bashrc, which interferes with the communication between bash and Emacs.

Ill try and reproduce the problem with the exact same versions of Emacs and bash to figure out whether this is a version problem and update this issue with the result.

If I understood correctly your last message, you basically turned off completion everywhere. This is unfortunate. There are other things you could try instead, until the underlying issue is fixed:

szermatt commented 4 months ago

Emacs version 30.0.50 is a development version, which means that a lot of things can go wrong and I'll have trouble testing with the exact same version you're using.

Did you try running with a stable version of Emacs, such as 29.4? Do you have the same issues?

szermatt commented 4 months ago

Ill try and reproduce the problem with the exact same versions of Emacs and bash to figure out whether this is a version problem and update this issue with the result.

I tried with the head version of Emacs and bash 5.2.26. This combination seems to work.

From the error output, it seems that Emacs thinks that bash has been initialized, when it hasn't. This typically happens when running remote shell from ssh or shells within a docker instance - or even afterwards, trying to run local completion. The latest version of emacs-bash-completion contains change that are meant to address such issues. Please try the latest version of emacs-bash-completion from melpa instead of melpa-stable, or directly from github.