Skip to content

Commit 22187aa

Browse files
committed
add completion
1 parent 8c87158 commit 22187aa

4 files changed

Lines changed: 71 additions & 4 deletions

File tree

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ RUN sed -i 's/^UMASK\s*022/UMASK 002/' /etc/login.defs
55
RUN usermod -aG www-data vscode
66

77
# Add glow for formatting command usage output (and because it's just nice)
8-
sudo mkdir -p /etc/apt/keyrings
9-
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
10-
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
8+
RUN mkdir -p /etc/apt/keyrings \
9+
&& curl -fsSL https://repo.charm.sh/apt/gpg.key | gpg --dearmor -o /etc/apt/keyrings/charm.gpg \
10+
&& echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | tee /etc/apt/sources.list.d/charm.list
1111

1212
# Install MariaDB and Redis and PHP (incl Apache) and Cypress dependencies
1313
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ I frequently invoke `uceap refresh-content` to reset my local environment after
2222
> drush $DRUSH_TASK
2323
> ```
2424
25-
Sometimes a process can die or port forwarding can fail. `uceap devcontainer-post-start` runs a few commands that should get things working again. (Again, shell completion makes this `uce<TAB>post-s<TAB>`).
25+
Sometimes a process can die or port forwarding can fail. `uceap devcontainer-post-start` runs a few commands that should get things working again. (Again, shell completion makes this `uce<TAB>sta<TAB>`).
2626
2727
Using devcontainers facilitates treating local environments as ephemeral: they're quick and easy to set up. Treat them as safe to destroy because you can always create a new one (or multiple new ones, to suit your needs). One thing you might miss is your shell history. Check out [Atuin](https://atuin.sh/) to sync your shell history across environments. `Control-R` has never looked so good 😎
2828

local/etc/uceap.d/completion.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
function completion() {
2+
commands=("${funcs[@]//_/-}")
3+
if [ $# -eq 1 ]; then
4+
shell="$1"
5+
case "$shell" in
6+
bash)
7+
echo complete -W \"${commands[*]}\" uceap
8+
;;
9+
zsh)
10+
echo "_uceap() { _arguments \"1: :(${commands[*]})\" }"
11+
echo "compdef _uceap uceap"
12+
;;
13+
*)
14+
echo "[error] Unsupported shell: $shell"
15+
return 1
16+
;;
17+
esac
18+
else
19+
echo "[error] Invalid number of arguments"
20+
return 1
21+
fi
22+
}
23+
24+
_completion_desc="generate shell completion scripts"
25+
_completion_help='
26+
Generate shell completion scripts for UCEAP CLI commands.
27+
28+
# Usage
29+
30+
``` sh
31+
uceap completion bash
32+
uceap completion zsh
33+
```
34+
35+
## bash
36+
37+
First, ensure that you install `bash-completion` using your package manager.
38+
39+
After, add this to your `~/.bash_profile`:
40+
41+
``` bash
42+
eval "$(uceap completion bash)"
43+
```
44+
45+
## zsh
46+
47+
Generate a `_uceap` completion script and put it somewhere in your `$fpath`:
48+
49+
``` zsh
50+
uceap completion zsh > /usr/local/share/zsh/site-functions/_uceap
51+
```
52+
53+
Ensure that the following is present in your `~/.zshrc`:
54+
55+
``` zsh
56+
autoload -U compinit
57+
compinit -i
58+
```
59+
60+
Zsh version 5.7 or later is recommended.
61+
'

local/etc/uceap.d/devcontainer_on_create.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ function devcontainer_on_create() {
4848
mkdir -p $WORKSPACE_FOLDER/.vscode
4949
cp /usr/local/share/vscode/* $WORKSPACE_FOLDER/.vscode/
5050

51+
# Setup shell completion
52+
uceap completion bash | sudo sh -c "cat > /etc/bash_completion.d/uceap"
53+
uceap completion zsh | sudo sh -c "cat > /usr/local/share/zsh/site-functions/_uceap"
54+
# Force loading of the completion script because I can't get it to autoload
55+
echo "autoload -Uz _uceap && compdef _uceap uceap" >> ~/.zshrc
56+
5157
# Run local devcontainer lifecycle scripts
5258
if [ -x .devcontainer/onCreate.sh ]; then
5359
.devcontainer/onCreate.sh

0 commit comments

Comments
 (0)