-
Notifications
You must be signed in to change notification settings - Fork 1
/
vyxnix.fish
111 lines (95 loc) · 3.27 KB
/
vyxnix.fish
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
function vyxnix -d "vyxos nix3 launcher"
# Principal nix3 launcher.
#
# "develop" and "shell" are treated specially:
# vyxnix develop -> nix develop --command fish
# vyxnix develop x y z -> nix develop x y z --command fish
# vyxnix develop x -- y z -> nix develop x --command fish -c "y z"
# vyxnix develop x --command y z -> nix develop x --command y z
# "d/s" below refers to these cases.
#
# "run" is also treated specially:
# vyxnix run xyz -> nix run nixpkgs#xyz
# vyxnix run abc#def -> nix run abc#def
# vyxnix run uvw -- nyonk -> nix run nixpkgs#uvw -- nyonk
#
# !x=y translates to --override-input x y.
# Default options (specify --vyx-no-defaults to omit):
set -f defaultargs -L --keep-going
# Specify --vyx-dry-run to echo the command that would be executed.
# $state: "args", "command", "run"
# - "args" is the initial state.
# - (d/s only) "command" is entered when "--command" is encountered.
# All remaining arguments are appended to $args.
# - (d/s only) "run" is entered when "--" is encountered.
# All remaining arguments are appended to $run.
set -f state args
# $args: arguments passed to the command, not including any 'run'.
set -f args
# $run: run arguments, passed to the command (fish).
set -f run
# $command: the nix3 subcommand to run.
set -f command $argv[1]
set -e argv[1]
# $ds: 1 if develop or shell, 0 otherwise.
if test "$command" = "develop" -o "$command" = "shell"
set -f ds 1
else
set -f ds 0
end
# $nix: ["nix"] normally, ["echo" "nix"] if we're doing a dry run
set -f nix nix
for arg in $argv
switch $state
case args
if test "$arg" = "--vyx-no-defaults"
set defaultargs
continue
end
if test "$arg" = "--vyx-dry-run"
set -p nix echo
continue
end
if string match -qr '\A!(?<input>[^=]+)=(?<override>.+)\z' -- "$arg"
set -a args --override-input "$input" "$override"
continue
end
if test "$arg" = "--command" -a "$ds" -eq 1
set -a args --command
set state command
else if test "$arg" = "--" -a "$ds" -eq 1
set state run
else if test "$command" = "run"
if string match -qr '#' -- "$arg"
# nr abc#def ...
set -a args $arg
set state command
else if string match -qr '\A-' -- "$arg"
# nr --xyz ...
set -a args $arg
else
# nr abc ...
set -a args "nixpkgs#$arg"
set state command
end
else
set -a args $arg
end
case command
set -a args $arg
case run
set -a run $arg
end
end
if test "$state" = run
$nix $command $defaultargs $args --command fish -c (string escape -- $run | string join ' ')
else
if test "$state" = args -a "$ds" -eq 1
set -a args --command fish
end
$nix $command $defaultargs $args
end
end
complete -c vyxnix -l vyx-no-defaults -d "omit the default arguments passed by vyxnix"
complete -c vyxnix -l vyx-dry-run -d "do a dry run of this command; i.e. echo what would be run"
complete -c vyxnix -w nix