Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/howto/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ These guides will help you use Dune's features in your project.
homebrew-package
use-opam-alongside-dune-package-management
configure-editors-with-package-management
shell-completion
set-up-ci-with-package-management
customize-dev-tools-lock-directories
use-multiple-build-contexts
48 changes: 48 additions & 0 deletions doc/howto/shell-completion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
How to Set Up Shell Command Completion
======================================

Shell command completion refers to a common feature in various shells:
hitting \<TAB\> after a partially-typed command will print matching suggestions.
This can apply to command names, flags, arguments, filenames...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only true for command names and flags at the moment of writing. Let's not over-promise at this point and be accurate. If this document is stale when we add new completion features that's fine, it can always be updated.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aim here was to have a first paragraph that is a definition of what the term even means in a general sense, and right after that I specify what dune offers
do you think mentionning filenames here is ambiguous or over-promising?


Dune offers completion for commands, subcommands, and flags, for `bash`, `zsh`, and `powershell`.
The various shells and systems require specific configuration setups,
and this document aims to help users get completion running.

Bash
----

Command completion for bash might require [bash-completion](https://github.com/scop/bash-completion).
You will then need to create the bash completion script (by running `dune completion bash`)
and write that script to an appropriate place: by default that should be
`~/.local/share/bash-completion/completions/dune` for a user-local configuration,
or `/usr/local/share/bash-completion/completions/dune` for a system-wide installation.
If you use `opam` switches and wish to have switch-local completion,
add the script to `<switch prefix>/share/bash-completion/completions/dune`.

A different path would be to add to your `.bashrc` the following line: `eval "$(dune completion bash)"`.

You might need to restart your shell to see the effects.

Zsh
---

Command completion for zsh might require [zsh-completions](https://github.com/zsh-users/zsh-completions).
You will then need to create the zsh completion script (by running `dune completion zsh`)
and write that script to a place that will get autoloaded: directories present
in your `$fpath` (by default it should be `~/.local/share/zsh/site-functions`).
If you wish to create a dedicated completion directory and add it to your `$fpath`,
be sure to add the following in your `.zshrc` but **before** any call to `compinit`:
`fpath+=<your dir>`.

You might need to restart your shell to see the effects.

PowerShell
----------

Command completion for powershell should work out of the box:
simply run `dune completion powershell >> $PROFILE.CurrentUserCurrentHost`.
Alternatively, add the following to your profile script:
`dune completion powershell | Out-String | Invoke-Expression`.

You might need to restart your shell to see the effects.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about the one above the alternative, so probably best move it up.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually all of the shells have this same flow issue

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure what may or may not require a shell restart, so I added up at the end of each section to be sure

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The eval-like steps don't require a restart, anything editing configuration likely does. I'm certain about bash and powershell but not about zsh.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the eval commands are to be added to bashrc and equivalent, thus requiring a restart as well

Loading