[Haskell-cafe] Autocomplete command line options with GHC 7.8

16 views
Skip to first unread message

Jan Stolarek

unread,
Apr 16, 2014, 11:19:30 AM4/16/14
to haskell-cafe, glasgow-ha...@haskell.org
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.
_______________________________________________
Haskell-Cafe mailing list
Haskel...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Philip Dexter

unread,
Apr 16, 2014, 12:03:38 PM4/16/14
to Jan Stolarek, glasgow-ha...@haskell.org, haskell-cafe
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)

Jan Stolarek

unread,
Apr 16, 2014, 12:49:41 PM4/16/14
to Philip Dexter, Herbert Valerio Riedel, glasgow-ha...@haskell.org, haskell-cafe
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

Philip Dexter

unread,
Apr 16, 2014, 12:54:48 PM4/16/14
to Jan Stolarek, glasgow-ha...@haskell.org, haskell-cafe

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
Reply all
Reply to author
Forward
0 new messages