optparse-applicative icon indicating copy to clipboard operation
optparse-applicative copied to clipboard

Use bash from $SHELL when it makes sense

Open roberth opened this issue 5 years ago • 2 comments

This fixes file completion in cases where a virtual environment with a non-interactive bash is loaded with direnv, nix-shell or similar.

It solves the error:

$ mycommand --file <TAB>bash: compgen: command not found
bash: compgen: command not found
bash: compgen: command not found

roberth avatar Oct 14 '20 19:10 roberth

Hi thanks for contributing to optparse!

I'll be honest, I'm very conflicted on this, though happy to discuss further.

What you've shown in your terminal printout is awful! We just regurgitate stderr of the base process into the user's shell when really, they don't want that. What I'm thinking is changing the bashCompleter function to something like this:

bashCompleter :: String -> Completer
bashCompleter action = Completer $ \word -> do
  let cmd = unwords ["compgen", "-A", action, "--", requote word]
  (ec, _, result) <-
    readProcessWithExitCode "bash" ["-c", cmd] ""

  return $
    if ec == ExitSuccess then
      lines result
    else
      []

Here we get rid of a exception handler and won't spew error messages to their terminal when they hit tab. Your solution won't fix that in the general case, but could reduce it for some.

I don't know, is that acceptable?

HuwCampbell avatar Nov 06 '20 09:11 HuwCampbell

A change like that will make it practically impossible to troubleshoot, unless someone is dead set on solving a minor inconvenience.

roberth avatar Nov 06 '20 09:11 roberth