Autocomplete command line options with GHC 7.8

Hi all, GHC 7.8 adds --show-options flag that prints all supported command line flags on standard output. This can be used to enable autocompletion of command line options for ghc in shells that support autocompletion. If you're using bash add this snippet to your ~/.bashrc file: <<<<<<<<<<<<< START # Autocomplete GHC commands _ghc() { local envs=`ghc --show-options` # get the word currently being completed local cur=${COMP_WORDS[$COMP_CWORD]} # the resulting completions should be put into this array COMPREPLY=( $( compgen -W "$envs" -- $cur ) ) } complete -F _ghc -o default ghc <<<<<<<<<<<< END Enjoy. Janek PS. I also added a wiki page: https://ghc.haskell.org/trac/ghc/wiki/AutocompleteGHCFlags Feel free to add instructions for other shells.

On Wed, 16 Apr 2014, Jan Stolarek wrote:
PS. I also added a wiki page: https://ghc.haskell.org/trac/ghc/wiki/AutocompleteGHCFlags Feel free to add instructions for other shells.
Zsh autocompletion resides on the haskell wiki [1]. There are also updated versions of both _cabal and _ghc (PR pending) at [2]. _ghc also includes completions for ghci and ghc-pkg. [1] http://www.haskell.org/haskellwiki/Zsh [2] https://github.com/zsh-users/zsh-completions ps - I tried to register on trac to add this info to your page but my registration was marked as spam (even after answering a math question)

Thanks Philip.
ps - I tried to register on trac to add this info to your page but my registration was marked as spam (even after answering a math question) I believe you have to contact Herbert about that (CC'd).
In the meantime I added this information to GHC wiki, although it would be nice to be able to use --show-options under zsh as well. From my understanding scripts that you linked to need to be manually updated, whereas --show-options displays all flags defined in the code of GHC. Janek

On Wed, 16 Apr 2014, Jan Stolarek wrote:
In the meantime I added this information to GHC wiki, although it would be nice to be able to use --show-options under zsh as well. From my understanding scripts that you linked to need to be manually updated, whereas --show-options displays all flags defined in the code of GHC.
Yes, that is true. There are tradeoffs. Zsh does provide a brief description of each auto-completed flag which you cannot achieve with --show-options. Perhaps it could be some sort of fallback where if an option and its description isn't provided, the plain result from --show-options could be used. Hmmm
participants (2)
-
Jan Stolarek
-
Philip Dexter