-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathshell-completion-test.nix
More file actions
67 lines (60 loc) · 1.77 KB
/
shell-completion-test.nix
File metadata and controls
67 lines (60 loc) · 1.77 KB
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
{
runCommand,
bash,
bash-completion,
zsh,
fish,
nushell,
cntr,
}:
runCommand "shell-completion-test"
{
nativeBuildInputs = [
bash
bash-completion
zsh
fish
nushell
];
}
''
set -euo pipefail
echo "=== Testing bash completion ==="
bash -c '
source ${bash-completion}/share/bash-completion/bash_completion
source ${cntr}/share/bash-completion/completions/cntr.bash
# Test that completion function exists
type _cntr
# Test completion for subcommands
COMP_WORDS=(cntr "")
COMP_CWORD=1
_cntr
echo "Bash completions: ''${COMPREPLY[*]}"
[[ " ''${COMPREPLY[*]} " == *" attach "* ]] || { echo "Missing attach"; exit 1; }
[[ " ''${COMPREPLY[*]} " == *" exec "* ]] || { echo "Missing exec"; exit 1; }
[[ " ''${COMPREPLY[*]} " == *" help "* ]] || { echo "Missing help"; exit 1; }
[[ " ''${COMPREPLY[*]} " == *" version "* ]] || { echo "Missing version"; exit 1; }
'
echo "=== Testing zsh completion ==="
zsh -f -c '
autoload -U compinit && compinit -u
source ${cntr}/share/zsh/site-functions/_cntr
# Test that completion function exists
whence -v _cntr | grep -q "function"
'
echo "=== Testing fish completion ==="
fish --no-config -c '
source ${cntr}/share/fish/vendor_completions.d/cntr.fish
# Test that completions are registered
complete -c cntr | grep -q attach
complete -c cntr | grep -q exec
'
echo "=== Testing nushell completion ==="
nu --no-config-file -c '
source ${cntr}/share/nushell/vendor/autoload/cntr.nu
# Test that the command is defined with completions
help cntr | str contains "attach"
help cntr | str contains "exec"
'
touch $out
''