Skip to content

Commit b2c7d17

Browse files
authored
feat(kubectl-helm-minikube): πŸ§‘β€πŸ’» add helm completion (#1080)
* feat(kubectl-helm-minikube): πŸ§‘β€πŸ’» add helm completion Like **kubectl**, **helm** supports **bash** and **zsh** command completion. * test(kubectl-helm-minikube): βœ… test helm bash completion * chore(kubectl-helm-minikube): πŸ”§ update feature version
1 parent 56233fd commit b2c7d17

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

β€Žsrc/kubectl-helm-minikube/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "kubectl-helm-minikube",
3-
"version": "1.1.10",
3+
"version": "1.2.0",
44
"name": "Kubectl, Helm, and Minikube",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/kubectl-helm-minikube",
66
"description": "Installs latest version of kubectl, Helm, and optionally minikube. Auto-detects latest versions and installs needed dependencies.",

β€Žsrc/kubectl-helm-minikube/install.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,16 @@ if [ ${HELM_VERSION} != "none" ]; then
311311
echo '(!) Helm installation failed!'
312312
exit 1
313313
fi
314+
315+
# helm bash completion
316+
helm completion bash > /etc/bash_completion.d/helm
317+
318+
# helm zsh completion
319+
if [ -e "${USERHOME}/.oh-my-zsh" ]; then
320+
mkdir -p "${USERHOME}/.oh-my-zsh/completions"
321+
helm completion zsh > "${USERHOME}/.oh-my-zsh/completions/_helm"
322+
chown -R "${USERNAME}" "${USERHOME}/.oh-my-zsh"
323+
fi
314324
fi
315325

316326
# Install Minikube, verify checksum
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
command=$1
4+
expected=$2
5+
6+
echo -e "Checking completion for command '$command'..."
7+
8+
# Send command as a character stream, followed by two tab characters, into an interactive bash shell.
9+
# Also note the 'y' which responds to the possible Bash question "Display all xxx possibilities? (y or n)".
10+
# Bash produces the autocompletion output on stderr, so redirect that to stdout.
11+
# The sed bit captures the lines between Header and Footer (used as output delimiters).
12+
# The first grep removes the "Display all" message (that is atomatically answered to "y" by the script).
13+
# The last grep filters the output to lines containing the expected result.
14+
COMPLETE_OUTPUT=$(echo if false\; then "Header"\; $command$'\t'$'\t'y\; "Footer" fi | bash -i 2>&1 | sed -n '/Header/{:a;n;/Footer/q;p;ba}' | grep -v ^'Display all ')
15+
echo -e "\nCompletion output:\n"
16+
echo -e "$COMPLETE_OUTPUT"
17+
echo -e "\n"
18+
19+
FILTERED_COMPLETE_OUTPUT=$(echo "$COMPLETE_OUTPUT" | grep "$expected")
20+
21+
if [ -z "$FILTERED_COMPLETE_OUTPUT" ]; then
22+
echo -e "Completion output does not contains '$expected'."
23+
exit 1
24+
else
25+
echo -e "Completion output contains '$expected'."
26+
exit 0
27+
fi

β€Žtest/kubectl-helm-minikube/test.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,15 @@ check "kube" kubectl
1010
check "helm" helm version
1111
check "minikune" minikube version
1212

13+
# By default bash complete is disabled for the root user
14+
# Enable it by replacing current ~/.bashrc with the /etc/skel/.bashrc file
15+
mv ~/.bashrc ~/.bashrc.bak
16+
cp /etc/skel/.bashrc ~/
17+
18+
check "helm-bash-completion-contains-version-command" ./checkBashCompletion.sh "helm " "version"
19+
20+
# Restore original ~/.bashrc
21+
mv ~/.bashrc.bak ~/.bashrc
22+
1323
# Report result
1424
reportResults

0 commit comments

Comments
Β (0)