-
Notifications
You must be signed in to change notification settings - Fork 216
/
shell.nix
61 lines (54 loc) · 1.85 KB
/
shell.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{ args ? {} , shell ? "bash" }:
let
shared = import ./nix/shared.nix args;
static = shared.possibly-static;
in
shared.pkgs.runCommand "dhall-shell-${shell}" {
buildInputs = [
static.dhall
static.dhall-json
static.dhall-bash
static.dhall-nix
static.dhall-yaml
];
shellHook = ''
echo "Dhall core tools shell"
echo "USAGE EXAMPLES"
echo " Default (GHC version ${(import ./nix/shared.nix {}).pkgs.haskellPackages.ghc.version}, option completions shell - bash):"
echo " $ nix-shell"
echo " Overriding default GHC compiler (see ./nix/shared.nix for available options):"
echo " $ nix-shell --arg args '{ compiler = "ghc861"; }'"
echo " Overriding option completion shell flavor:"
echo " $ nix-shell --argstr shell zsh"
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
'';
} ""