Skip to content

Commit 4de78e4

Browse files
committed
Bash completion
1 parent cd4da41 commit 4de78e4

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

bash_completion

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash -e
2+
3+
__cppsm_complete() {
4+
local IFS=$' \t\n'
5+
COMPREPLY=()
6+
local PREVIOUS="${3#\"}"
7+
PREVIOUS="${PREVIOUS%\"}"
8+
local CURRENT="${2#\"}"
9+
CURRENT="${CURRENT%\"}"
10+
case "$PREVIOUS" in
11+
cppsm)
12+
# shellcheck disable=SC2207
13+
COMPREPLY=($(compgen -W "add build build-watch hello init list remove setup test test-watch update-all" -- "$CURRENT"))
14+
;;
15+
add)
16+
# shellcheck disable=SC2207
17+
COMPREPLY=($(compgen -W "equipment requires" -- "$CURRENT"))
18+
;;
19+
equipment|requires)
20+
if command -v jq > /dev/null && command -v curl > /dev/null && command -v sed > /dev/null; then
21+
# shellcheck disable=SC2207
22+
COMPREPLY=($(curl -s "https://api.github.com/search/repositories?q=topic:cppsm+${CURRENT##*/}" | \
23+
jq '.items | .[] | .clone_url'))
24+
fi
25+
;;
26+
https:*.git)
27+
if command -v sed > /dev/null; then
28+
# shellcheck disable=SC2207
29+
COMPREPLY=($(git ls-remote --heads "$PREVIOUS" | sed -e 's#[^ ]*\s*refs/heads/##g'))
30+
fi
31+
;;
32+
*)
33+
;;
34+
esac
35+
}
36+
37+
complete -F __cppsm_complete -o default cppsm

0 commit comments

Comments
 (0)