szermatt / emacs-bash-completion

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

bash completion bombs, kills shell process #63

Closed tvraman closed 1 year ago

tvraman commented 1 year ago

Installed from melpa: /home/raman/.emacs.d/elpa/bash-completion-20230208.1903

bash-completions from this version bombs, error from bash-completion-debug follows.

This buffer contains information about the last completion command and the BASH process it was sent to. This can help you figure out what's happening.

If it doesn't, go to https://github.com/szermatt/emacs-bash-completion/issues/new to create a new issue that describes:

Then add a copy of the information below:

commandline: <<EOF function ebcnohistory { local c=$((HISTCMD-1)) maj=${BASH_VERSINFO[0]} min=${BASH_VERSINFO[1]}; if [[ $maj -eq 5 && $min -ge 1 || $maj -gt 5 ]]; then c=$((c+1)); fi; history -d $c &>/dev/null || true;}; function ebcpre { set +x; set +o emacs; set +o vi; echo "==emacs==bash=${BASH_VERSINFO[0]}==."; if [[ -z "${ebcps1}" ]]; then ebcps1="$PS1"; ebcpc="$PROMPT_COMMAND"; fi; PROMPT_COMMAND='PS1='\''==emacs==ret=$?==.'\'';PROMPT_COMMAND='\''ebcr=$?;PS1="${ebcps1}";PROMPT_COMMAND="${ebcpc}";unset ebcps1 ebcpc;if [[ -n "$PROMPT_COMMAND" ]]; then (exit $__ebcr); eval "$PROMPT_COMMAND";fi;'\'''; ebcnohistory 1;} && { ebcpre; __ebcnohistory; } EOF

error: "short-timeout" buffer-string: <<EOF bash: __ebcpre: command not found EOF

process: #<process shell<1>>

ERROR: Process is dead. Information collection is incomplete. Please retry

emacs-version: "30.0.50" context: #s(completion "./ch" ("./ch") 0 "./ch" 15 "./ch" nil nil nil nil)

szermatt commented 1 year ago

Thank you for the bug report! This is puzzling and worrying. I haven't been able to reproduce. That version, downloaded from melpa, works for me on a vanilla install of Emacs 28. I haven't tried Emacs 30.0 yet.

I'd like to try and reproduce the error with the exact version of Bash you're using. If you execute the following in an Emacs shell buffer:

echo $BASH_VERSION

What's the result?

When the Bash process crashed bash-completion.el was trying to set things up with the Bash prompt and history. Have you set PROMPT_COMMAND ? If yes, would you mind trying again with

PS1='$ ' PROMPT_COMMAND=''

in your .bashrc? It's a long shot, I don't see how anything in PROMPT_COMMAND could possibly interfere, but that's all I can think about.

ss2 commented 1 year ago

Can confirm. Using checkout 796a806c5531fc20afea590ba3c1d8a42fb793fc.

I temporarily set PS1=$ and cleared $PROMPT_COMMAND as suggested and can reproduce it. But there's a difference I notice too: If I spawn a new shell and enter ls --tab, then completion will be fine afterwards and it works as expected. But entering lstab first breaks it from the beginning.

My output from bash-completion-debug via emacs -Q and manually loading bash-completion:

commandline: <<EOF
function __ebcnohistory {  local c=$((HISTCMD-1)) maj=${BASH_VERSINFO[0]} min=${BASH_VERSINFO[1]};  if [[ $maj -eq 5 && $min -ge 1 || $maj -gt 5 ]]; then    c=$((c+1));  fi;  history -d $c &>/dev/null || true;}; function __ebcpre {  set +x; set +o emacs; set +o vi;  echo "==emacs==bash=${BASH_VERSINFO[0]}==.";  if [[ -z "${__ebcps1}" ]]; then     __ebcps1="$PS1";    __ebcpc="$PROMPT_COMMAND";  fi;  PROMPT_COMMAND='PS1='\''==emacs==ret=$?==.'\'';PROMPT_COMMAND='\''__ebcr=$?;PS1="${__ebcps1}";PROMPT_COMMAND="${__ebcpc}";unset __ebcps1 __ebcpc;if [[ -n "$PROMPT_COMMAND" ]]; then  (exit $__ebcr); eval "$PROMPT_COMMAND";fi;'\''';  __ebcnohistory 1;} && { __ebcpre; __ebcnohistory; }
EOF

error: "short-timeout"
buffer-string: <<EOF
bash: __ebcpre: command not found
EOF

process: #<process shell>

ERROR: Process is dead. Information collection is incomplete.
Please retry

emacs-version: "28.2"
context: #s(completion "ls"
              ("ls")
              0 "ls" 3 "ls" nil nil nil nil)
szermatt commented 1 year ago

Thank you! I can reproduce it now and I'm working on a fix.

szermatt commented 1 year ago

The patch above seem to fix the problem. It fixes a real bug in bash-completion.el, but not one that should have caused Bash to crash! I'm still puzzled as to exactly what happened.

tvraman commented 1 year ago

ss2 @.***> writes:

Matches my experience exactly.

Where exactly did you unset PROMPT_COMMAND; in my case i have that set to a bash function that plays a sound as a function of the exit code of the previous command.

Also I'm observing failures on my desktop (not laptop) with an error that __ebcpre is not defined; that goes away if I turn on bash-completion-use-separate-processes to t (something I've never had to do in all these years)

Can confirm. Using checkout 796a806.

I temporarily set PS1=$ and cleared $PROMPT_COMMAND as suggested and can reproduce it. But there's a difference I notice too: If I spawn a new shell and enter ls --tab, then completion will be fine afterwards and it works as expected. But entering lstab first breaks it from the beginning.

My output from bash-completion-debug via emacs -Q and manually loading bash-completion:

commandline: <<EOF function ebcnohistory { local c=$((HISTCMD-1)) maj=${BASH_VERSINFO[0]} min=${BASH_VERSINFO[1]}; if [[ $maj -eq 5 && $min -ge 1 || $maj -gt 5 ]]; then c=$((c+1)); fi; history -d $c &>/dev/null || true;}; function ebcpre { set +x; set +o emacs; set +o vi; echo "==emacs==bash=${BASH_VERSINFO[0]}==."; if [[ -z "${ebcps1}" ]]; then ebcps1="$PS1"; ebcpc="$PROMPT_COMMAND"; fi; PROMPT_COMMAND='PS1='\''==emacs==ret=$?==.'\'';PROMPT_COMMAND='\''ebcr=$?;PS1="${ebcps1}";PROMPT_COMMAND="${ebcpc}";unset ebcps1 ebcpc;if [[ -n "$PROMPT_COMMAND" ]]; then (exit $__ebcr); eval "$PROMPT_COMMAND";fi;'\'''; ebcnohistory 1;} && { ebcpre; __ebcnohistory; } EOF

error: "short-timeout" buffer-string: <<EOF bash: __ebcpre: command not found EOF

process: #

ERROR: Process is dead. Information collection is incomplete. Please retry

emacs-version: "28.2" context: #s(completion "ls" ("ls") 0 "ls" 3 "ls" nil nil nil nil)

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

--

Thanks,

--Raman(I Search, I Find, I Misplace, I Research) ♈ Id: kg:/m/0285kf1 🦮

tvraman commented 1 year ago

Thank you! Goes without saying that this is an indispensible package; thank you for fixing it so quickly.

--

Thanks,

--Raman(I Search, I Find, I Misplace, I Research) ♈ Id: kg:/m/0285kf1 🦮

szermatt commented 1 year ago

No problems!

I unset PROMPT_COMMAND temporarily when executing the first of several Bash commands that do the completion and set it back to what it was at the end. Without it, you'd hear the prompt sound several times when completing, as bash-completion.el executes several commands in the background.

With the latest versions, you probably hear the prompt sound when you shouldn't once during completion the very first time you press TAB in a buffer. That's likely confusing. I think I can fix that.

Setting bash-completion-use-separate-processes to t would indeed avoid the whole issue with prompts and also avoids this bug, but there's of course a cost: it's slower and won't take into account any changes you might have made, such as new functions.

By the way, I finally figured out what happened. The following seems to reliably crash Bash compgen -A function > >(__notfound) This is fun! Who would do something like that ? ;) I filed a bug https://savannah.gnu.org/support/index.php?110850

tvraman commented 1 year ago

I am still unsure where to unset PROMPT_COMMAND. Also I hear the audio cue multiple times when a new shell buffer is created --- likely related.

--

Thanks,

--Raman(I Search, I Find, I Misplace, I Research) ♈ Id: kg:/m/0285kf1 🦮

szermatt commented 1 year ago

I just asked you to unset PROMPT_COMMAND for me to figure things out. You should be able to leave PS1 and PROMPT_COMMAND as you want them and not worry about bash-completion.el.

With the fix, I expect you'll still hear the audio cue when you shouldn't. I'm working on a separate fix for that.

tvraman commented 1 year ago

Stephane Zermatten @.***> writes:

Thanks!

I now understand your earlier messages after pulling the latest update and looking at the code in bash-completions.el

I am now able to use it effectively without having to use a separate process for completion; looking forward to silencing the redundant sound cues. In case you didn't guess, I cannot see which is why I have those sounds in PROMPT_COMMAND

-us> I just asked you to unset PROMPT_COMMAND for me to figure things out. You should be able to leave PS1 and

PROMPT_COMMAND as you want them.

With the fix, I expect you'll still hear the audio cue when you shouldn't. I'm working on a separate fix for that.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

--

Thanks,

--Raman(I Search, I Find, I Misplace, I Research) ♈ Id: kg:/m/0285kf1 🦮

szermatt commented 1 year ago

The latest commit avoids executing PROMPT_COMMAND during completion, even the first time; there shouldn't be any confusing sound cues anymore.

tvraman commented 1 year ago

Works like a charm after updating from melpa and restarting emacs!

--

Thanks,

--Raman(I Search, I Find, I Misplace, I Research) ♈ Id: kg:/m/0285kf1 🦮