Skip to content

Commit 3b73b7a

Browse files
committed
Merge branch 'stable'
2 parents 24bf663 + e9b126c commit 3b73b7a

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

doc/shell_autocompletion.md

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,69 @@
22

33
# Shell auto-completion
44

5-
The following adds support for the tab completion of standard Stack arguments in
6-
the Bash shell or the Z shell (Zsh). Completion of file names and executables
7-
within Stack is still lacking. For further information, see issue
5+
The following adds support for the tab completion of standard Stack arguments to
6+
the following shell programs: Bash, Zsh (the Z shell) and fish. Completion of
7+
file names and executables within Stack is still lacking. For further
8+
information, see issue
89
[#823](https://github.com/commercialhaskell/stack/issues/832).
910

10-
=== "Bash"
11+
!!! info
1112

12-
Issue the following command or add it to your `~/.bashrc` file:
13+
Stack's completion library provides
14+
[hidden options](https://github.com/pcapriotti/optparse-applicative#bash-zsh-and-fish-completions)
15+
for Bash, Zsh, and fish which output commands used for shell
16+
auto-completion. For example:
1317

1418
~~~bash
15-
eval "$(stack --bash-completion-script stack)"
16-
~~~
19+
$ stack --bash-completion-script stack
20+
_stack()
21+
{
22+
local CMDLINE
23+
local IFS=$'\n'
24+
CMDLINE=(--bash-completion-index $COMP_CWORD)
1725

18-
!!! info
26+
for arg in ${COMP_WORDS[@]}; do
27+
CMDLINE=(${CMDLINE[@]} --bash-completion-word $arg)
28+
done
1929

20-
Stack's hidden option `--bash-completion-script <stack_executable_name>`
21-
outputs a command that can be evaluated by Bash. For example:
30+
COMPREPLY=( $(stack "${CMDLINE[@]}") )
31+
}
2232

23-
~~~text
24-
stack --bash-completion-script stack
25-
_stack.exe()
26-
{
27-
local CMDLINE
28-
local IFS=$'\n'
29-
CMDLINE=(--bash-completion-index $COMP_CWORD)
33+
complete -o filenames -F _stack stack
34+
~~~
3035

31-
for arg in ${COMP_WORDS[@]}; do
32-
CMDLINE=(${CMDLINE[@]} --bash-completion-word $arg)
33-
done
36+
=== "Bash"
3437

35-
COMPREPLY=( $(stack "${CMDLINE[@]}") )
36-
}
37-
~~~
38+
Add the output of the following command to your preferred completions file
39+
(e.g. `~/.config/bash_completions.d/stack`).
3840

39-
=== "Zsh"
41+
~~~bash
42+
stack --bash-completion-script $(which stack)
43+
~~~
4044

41-
The Zsh
42-
[manual](https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Completion-System)
43-
explains:
45+
You may need to `source` this.
4446

45-
> The function `bashcompinit` provides compatibility with bash’s
46-
programmable completion system. When run it will define the functions,
47-
`compgen` and `complete` which correspond to the bash builtins with the same
48-
names. It will then be possible to use completion specifications and
49-
functions written for bash.
47+
=== "Zsh"
5048

51-
Consequently, you must:
49+
Add the output of the following command to your preferred completions file
50+
(e.g. `~/.config/zsh/completions/_stack`).
5251

53-
1. launch `compinint`
54-
2. launch `bashcompinit`
55-
3. eval Stack's Bash completion script
52+
~~~zsh
53+
stack --zsh-completion-script $(which stack)
54+
~~~
5655

57-
Issue the following commands or that them to your `~/.zshrc` file:
56+
You won't need to `source` this, but do update your `fpath`:
5857

5958
~~~zsh
60-
autoload -U +X compinit
61-
compinit
62-
autoload -U +X bashcompinit
63-
bashcompinit
64-
eval "$(stack --bash-completion-script stack)"
59+
fpath=($HOME/.config/zsh/completions $fpath)
60+
autoload -U compinit && compinit
6561
~~~
6662

67-
!!! info
63+
=== "fish"
64+
65+
Add the output of the following command to your preferred completions file
66+
(e.g. `~/.config/fish/completions/stack.fish`).
6867

69-
If you already have quite a large `.zshrc` file, or if you use
70-
`oh-my-zsh`, `compinit` will probably already be loaded.
68+
~~~fish
69+
stack --fish-completion-script $(which stack)
70+
~~~

0 commit comments

Comments
 (0)