szermatt / emacs-bash-completion

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

completions in docker shells, how to? #58

Closed benjamin-asdf closed 1 year ago

benjamin-asdf commented 1 year ago

Currently when I start in interactive shell in a docker image, bash-completions locks up. I recently found bash-completion-reset and will try this for remote sessions.

(setf bash-completion-use-separate-processes t) at least doesn't make it lock up but I get completions from my bash session but I want the ones from inside the docker.

Can I somehow add basic fallback completions?

szermatt commented 1 year ago

The way bash works with bash-completion-use-separate-processes set to nil, it should work from within a docker image, just like it works from within a remote shell, started with ssh.

There's a catch, however, that results in very annoying lock ups: when you change shells (when you go from a local shell to a remote one or to a shell inside a docker image) after already having asked for completion on the current buffer, you must call bash-completion-refresh before you ask for a new completion.

Taking ssh as an example:

1 $ ls /us <TAB> 
2 $ ssh otherhost
3 $ ls /us <TAB>

bash-completion-debug must be called on line 3, before pressing TAB, or completion will freeze at line 3.

I haven't been able to find a good solution to this very annoying problem. Ideally, it'd be possible to detect that there's been a change, but I haven't found a reliable way of doing it.

So I'd suggest to either always remember to call bash-completion-refresh at the right time (that hasn't worked for me; I keep forgetting) or always start your shell directly as a remote or docker shell with a custom Emacs command.

Because if you do the following in a fresh buffer:

1 $ ssh otherhost
2 $ ls /us <TAB>

Everything works, because the first time completion is called, the shell is already remote.

Can I somehow add basic fallback completions?

I'm not sure what you mean by that. Is this what you get if you disable bash-completion.el entirely?

Edit: the correct command is bash-completion-refresh not bash-completion-reset

benjamin-asdf commented 1 year ago

I see ok. I will check around with this. One idea but not an ideal one is to call "refresh" everytime the current shell prompt changes maybe. Nervermind about "basic". I was thinking along the lines of completing the output of ls etc. But I see how that is not "bash-completion", then.

szermatt commented 1 year ago

The latest version should fix the issues I described above. It's not necessary anymore to worry when starting bash subprocesses; bash-completion.el will do the right thing.