Skip to content

Commit

Permalink
Fix zsh completion support (#1829)
Browse files Browse the repository at this point in the history
* Fix `zsh` completion support

Fixes #1827

* Add `dhall-docs` to `shell.nix`

Co-authored-by: Simon Jakobi <simon.jakobi@gmail.com>

Co-authored-by: Simon Jakobi <simon.jakobi@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 5, 2020
1 parent ae7f80c commit 19368ac
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ shared.pkgs.runCommand "dhall-shell-${shell}" {
static.dhall-nix
static.dhall-yaml
];

shellHook = ''
echo "Dhall core tools shell"
echo "USAGE EXAMPLES"
Expand All @@ -21,13 +22,40 @@ shared.pkgs.runCommand "dhall-shell-${shell}" {
echo " Overriding option completion shell flavor:"
echo " $ nix-shell --argstr shell zsh"
source <(dhall --${shell}-completion-script dhall)
source <(dhall-to-bash --${shell}-completion-script dhall-to-bash)
source <(dhall-to-nix --${shell}-completion-script dhall-to-nix)
source <(dhall-to-json --${shell}-completion-script dhall-to-json)
source <(dhall-to-yaml --${shell}-completion-script dhall-to-yaml)
source <(dhall-to-yaml-ng --${shell}-completion-script dhall-to-yaml-ng)
source <(json-to-dhall --${shell}-completion-script json-to-dhall)
source <(yaml-to-dhall --${shell}-completion-script yaml-to-dhall)
EXECUTABLES=(
dhall
dhall-docs
dhall-to-bash
dhall-to-nix
dhall-to-json
dhall-to-yaml
dhall-to-yaml-ng
json-to-dhall
yaml-to-dhall
)
if [ "${shell}" == "zsh" ]; then
# zsh does not support loading completions using `source`, so we need to
# add a special case for zsh
COMPLETIONS=$(mktemp -d)
export ZDOTDIR=$(mktemp -d)
trap "rm --recursive -- $COMPLETIONS $ZDOTDIR" INT EXIT
for EXECUTABLE in "''${EXECUTABLES[@]}"; do
"$EXECUTABLE" --${shell}-completion-script "$EXECUTABLE" > "$COMPLETIONS/_$EXECUTABLE"
done
echo "export fpath=($COMPLETIONS \$fpath)" >> "$ZDOTDIR/.zshenv"
echo 'autoload -Uz compinit' >> "$ZDOTDIR/.zshrc"
echo 'compinit' >> "$ZDOTDIR/.zshrc"
# nix-shell uses bash, even if your original shell was zsh
zsh -i
else
for EXECUTABLE in "''${EXECUTABLES[@]}"; do
source <("$EXECUTABLE" --${shell}-completion-script "$EXECUTABLE")
done
fi
'';
} ""

0 comments on commit 19368ac

Please sign in to comment.