File: build-shell-completions.sh

package info (click to toggle)
streamlink 8.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,568 kB
  • sloc: python: 51,299; sh: 184; makefile: 152
file content (29 lines) | stat: -rwxr-xr-x 802 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env bash
set -e

ROOT=$(git rev-parse --show-toplevel 2>/dev/null || realpath "$(dirname "$(readlink -f "${0}")")/..")

DIST="${ROOT}/completions"
PYTHON_DEPS=(streamlink_cli shtab)

declare -A COMPLETIONS=(
  [bash]="streamlink"
  # ZSH requires the file to be prefixed with an underscore
  [zsh]="_streamlink"
)

for dep in "${PYTHON_DEPS[@]}"; do
  python -c "import ${dep}" 2>&1 >/dev/null \
    || { echo >&2 "${dep} could not be found in your python environment"; exit 1; }
done

for shell in "${!COMPLETIONS[@]}"; do
  mkdir -p "${DIST}/${shell}"
  dist="${DIST}/${shell}/${COMPLETIONS[${shell}]}"
  python -m shtab \
    "--shell=${shell}" \
    --error-unimportable \
    streamlink_cli._parser.get_parser \
    > "${dist}"
  echo "Completions for ${shell} written to ${dist}"
done