Skip to content

Commit 1874c0d

Browse files
babaric-devskovhus
authored andcommitted
Add fallback mechanism if pkg-config fails
`COMPLETIONSRC`: path to sourced `bash_completion` If `pkg-config` fails to get `bash_completion` script: - use `brew` on macOS - use `PREFIX` on Linux
1 parent c5ae572 commit 1874c0d

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

server/src/get-options.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
#!/usr/bin/env bash
22

3+
# Try and get COMPLETIONSRC using pkg-config
34
COMPLETIONSDIR="$(pkg-config --variable=completionsdir bash-completion)"
4-
DATADIR="$(dirname "$(dirname "${COMPLETIONSDIR}")")"
55

6-
# Exit if bash-completion isn't installed.
7-
if (( $? != 0 ))
6+
if (( $? == 0 ))
7+
then
8+
COMPLETIONSRC="$(dirname "$COMPLETIONSDIR")/bash_completion"
9+
else
10+
# Fallback if pkg-config fails
11+
if [ "$(uname -s)" = "Darwin" ]
12+
then
13+
# Running macOS
14+
COMPLETIONSRC="$(brew --prefix)/etc/bash_completion"
15+
else
16+
# Suppose running Linux
17+
COMPLETIONSRC="${PREFIX:-/usr}/share/bash-completion/bash_completion"
18+
fi
19+
fi
20+
21+
# Validate path of COMPLETIONSRC
22+
if (( $? != 0 )) || [ ! -r "$COMPLETIONSRC" ]
823
then
924
exit 1
1025
fi
1126

12-
source "$DATADIR/bash-completion/bash_completion"
27+
source "$COMPLETIONSRC"
1328

1429
COMP_LINE="$*"
1530
COMP_WORDS=("$@")

0 commit comments

Comments
 (0)