From e1b5a89cee92ce9e792c2286c0403029bc2f4ae0 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Wed, 22 Apr 2020 20:12:57 +0200 Subject: [PATCH] Add bash-completion --- .bash-completion | 11 +++++++++++ README.md | 6 ++++++ app/ghcup/Main.hs | 8 +++++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 .bash-completion diff --git a/.bash-completion b/.bash-completion new file mode 100644 index 0000000..9df439b --- /dev/null +++ b/.bash-completion @@ -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 diff --git a/README.md b/README.md index 8987ffe..bfa2250 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/ghcup/Main.hs b/app/ghcup/Main.hs index 714c266..ec05a90 100644 --- a/app/ghcup/Main.hs +++ b/app/ghcup/Main.hs @@ -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 |] customExecParser (prefs showHelpOnError) - (info (opts <**> helper <**> versionHelp <**> numericVersionHelp) + (info (opts <**> helper <**> versionHelp <**> numericVersionHelp <**> listCommands) (footerDoc (Just $ text main_footer)) ) >>= \opt@Options {..} -> do