Skip to content

Commit 058b65c

Browse files
committed
fix(aws-cli): fix ZSH completion installation
The ZSH completer script provided by the aws/aws-cli repo is not set up to be used as a completer function, and thus cannot be dropped into a directory like ~/.oh-my-zsh/completions and be expected to work. This change also moves the completer to a more standard location for system-wide ZSH completions, and adds the necessary header to make it work as a completer.
1 parent 87bc907 commit 058b65c

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

src/aws-cli/install.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,14 @@ install() {
119119

120120
./aws/install
121121

122-
# kubectl bash completion
122+
# AWS bash completion
123123
mkdir -p /etc/bash_completion.d
124124
cp ./scripts/vendor/aws_bash_completer /etc/bash_completion.d/aws
125125

126-
# kubectl zsh completion
127-
if [ -e "${USERHOME}/.oh-my-zsh" ]; then
128-
mkdir -p "${USERHOME}/.oh-my-zsh/completions"
129-
cp ./scripts/vendor/aws_zsh_completer.sh "${USERHOME}/.oh-my-zsh/completions/_aws"
130-
chown -R "${USERNAME}" "${USERHOME}/.oh-my-zsh"
131-
fi
126+
# AWS zsh completion
127+
mkdir -p /usr/local/share/zsh/site-functions/
128+
cp ./scripts/vendor/aws_zsh_completer.sh /usr/local/share/zsh/site-functions/_aws
129+
sed -i '1s/^/#compdef aws\n/' /usr/local/share/zsh/site-functions/_aws
132130

133131
rm -rf ./aws
134132
}

test/aws-cli/scenarios.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,14 @@
44
"features": {
55
"aws-cli": {}
66
}
7+
},
8+
"zsh_completion": {
9+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
10+
"features": {
11+
"common-utils": {
12+
"installZsh": true
13+
},
14+
"aws-cli": {}
15+
}
716
}
817
}

test/aws-cli/zsh_completion.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Import test library for `check` command
6+
source dev-container-features-test-lib
7+
8+
# Check that the zsh completion file exists in the correct location
9+
check "zsh completion file installed" test -f /usr/local/share/zsh/site-functions/_aws
10+
11+
# Check that the completion file has the proper zsh completion header
12+
check "zsh completion file has compdef header" grep -q "^#compdef aws" /usr/local/share/zsh/site-functions/_aws
13+
14+
# Actual ZSH completion testing is a pain, so just ignoring it for now.
15+
16+
# Report result
17+
reportResults

0 commit comments

Comments
 (0)