Add bash-completion

This commit is contained in:
Julian Ospald 2020-04-22 20:12:57 +02:00
parent 5edebd57d9
commit e1b5a89cee
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
3 changed files with 24 additions and 1 deletions

11
.bash-completion Normal file
View File

@ -0,0 +1,11 @@
_ghcup()
{
local cur
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
if [[ ${#COMP_WORDS[*]} -le 2 ]]; then
COMPREPLY=($(compgen -W "$(ghcup --list-commands)" -- $cur))
fi
return 0
} &&
complete -F _ghcup ghcup

View File

@ -68,6 +68,12 @@ handles your haskell packages and can demand that [a specific version](https://c
For man pages to work you need [man-db](http://man-db.nongnu.org/) as your `man` provider, then issue `man ghc`. Manpages only work for the currently set ghc.
`MANPATH` may be required to be unset.
### Bash-completion
Depending on your distro and setup, install `.bash-completion` from this repo
as e.g. `/etc/bash_completion.d/ghcup` and make sure your bashrc sources the
startup script (`/usr/share/bash-completion/bash_completion` on some distros).
## Design goals
1. simplicity

View File

@ -654,6 +654,12 @@ main = do
<> help "Show the numeric version (for use in scripts)"
<> hidden
)
let listCommands = infoOption
"install set rm install-cabal list upgrade compile debug-info tool-requirements changelog"
( long "list-commands"
<> help "List available commands for shell completion"
<> internal
)
let main_footer = [i|Discussion:
ghcup installs the Glasgow Haskell Compiler from the official
@ -668,7 +674,7 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
customExecParser
(prefs showHelpOnError)
(info (opts <**> helper <**> versionHelp <**> numericVersionHelp)
(info (opts <**> helper <**> versionHelp <**> numericVersionHelp <**> listCommands)
(footerDoc (Just $ text main_footer))
)
>>= \opt@Options {..} -> do