Skip to content

Commit ede9c91

Browse files
committed
Require either curl or wget for url completion
1 parent a1beee0 commit ede9c91

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

bash_completion

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
#!/bin/bash -e
22

3-
if ! command -v curl > /dev/null; then
4-
>&2 echo "WARNING: Could not find curl ( https://curl.haxx.se/ )."
3+
if ! command -v curl > /dev/null && ! command -v wget > /dev/null; then
4+
>&2 echo "WARNING: Could not find either curl ( https://curl.haxx.se/ ) or wget ( https://www.gnu.org/software/wget/ )."
55
fi
66

77
if ! command -v jq > /dev/null; then
88
>&2 echo "WARNING: Could not find jq ( https://stedolan.github.io/jq/ )."
99
fi
1010

11+
__cppsm_query() {
12+
local URL="$1"
13+
local QUERY="$2"
14+
if command -v jq > /dev/null; then
15+
if command -v curl > /dev/null; then
16+
local DOWNLOAD_CMD=(curl -s "$URL")
17+
elif command -v wget > /dev/null; then
18+
local DOWNLOAD_CMD=(wget -qO- "$URL")
19+
else
20+
return 0
21+
fi
22+
"${DOWNLOAD_CMD[@]}" | jq "$QUERY"
23+
fi
24+
}
25+
1126
__cppsm_complete() {
1227
local IFS=$' \t\n'
1328
COMPREPLY=()
@@ -25,18 +40,14 @@ __cppsm_complete() {
2540
COMPREPLY=($(compgen -W "equipment requires" -- "$CURRENT"))
2641
;;
2742
clone)
28-
if command -v jq > /dev/null && command -v curl > /dev/null; then
29-
# shellcheck disable=SC2207
30-
COMPREPLY=($(curl -s "https://api.github.com/search/repositories?q=topic:cppsm+${CURRENT##*/}" | \
31-
jq '.items | .[] | .ssh_url'))
32-
fi
43+
# shellcheck disable=SC2207
44+
COMPREPLY=($(__cppsm_query "https://api.github.com/search/repositories?q=topic:cppsm+${CURRENT##*/}" \
45+
'.items | .[] | .ssh_url'))
3346
;;
3447
equipment|requires)
35-
if command -v jq > /dev/null && command -v curl > /dev/null; then
36-
# shellcheck disable=SC2207
37-
COMPREPLY=($(curl -s "https://api.github.com/search/repositories?q=topic:cppsm+${CURRENT##*/}" | \
38-
jq '.items | .[] | .clone_url'))
39-
fi
48+
# shellcheck disable=SC2207
49+
COMPREPLY=($(__cppsm_query "https://api.github.com/search/repositories?q=topic:cppsm+${CURRENT##*/}" \
50+
'.items | .[] | .clone_url'))
4051
;;
4152
https:*.git|git*.git)
4253
# shellcheck disable=SC2207

0 commit comments

Comments
 (0)