Skip to content

Conversation

@bastimeyer
Copy link
Member

@bastimeyer bastimeyer commented Sep 25, 2021

Resolves #2993

This builds shell completions files for BASH and ZSH via shtab, which unlike other tools I've looked up in the past can parse an argparse.ArgumentParser object:
https://github.com/iterative/shtab

It's also only a simple build step and no runtime dependencies are required for implementing shell completions, which is the ideal solution.

Unfortunately, it currently does only support BASH and ZSH. I would love to see FISH support in the future as well.


The shell completion files get built via ./script/build-shell-completions.sh and are optional in the data_files field in setup.py, just like the man pages.

This means the wheels will include these files when built prior to running setup.py, and pip will write them to

  • ${XDG_DATA_HOME:-${HOME}/.local/share}/bash-completion/completions/streamlink
  • ${XDG_DATA_HOME:-${HOME}/.local/share}/zsh/site-functions/_streamlink

or (if run as sudo - which shouldn't be done)

  • /usr/share/bash-completion/completions/streamlink
  • /usr/share/zsh/site-functions/_streamlink

when installing the wheel.


The sdist and build targets of setup.py don't include these optional data files.

Third party packagers of Streamlink can build the completion files via shtab themselves:

python -m shtab \
  "--shell=${shell}" \
  --error-unimportable \
  streamlink_cli.main.parser_helper \
  > "${dist}"

or

./script/build-shell-completions.sh
install -Dm644 build/shtab/bash/streamlink /usr/share/bash-completion/completions/streamlink
install -Dm644 build/shtab/zsh/_streamlink /usr/share/zsh/site-functions/_streamlink

For BASH, this requires the bash-completion package to be installed and it'll look up the completion files automatically.
https://github.com/scop/bash-completion/blob/master/README.md

For ZSH, the local completion path needs to be added to the config's fpath (I believe). I'm not a ZSH user, but the global path seems to be correct from what I can tell (according to Arch Linux's packaging at least). A confirmation would be appreciated.


[basti@basti-pc streamlink]$ streamlink -
Display all 102 possibilities? (y or n)

[basti@basti-pc streamlink]$ streamlink --player-
--player-args                --player-external-http       --player-fifo                --player-no-close
--player-continuous-http     --player-external-http-port  --player-http                --player-passthrough

@back-to back-to merged commit 1549c41 into streamlink:master Sep 26, 2021
@bastimeyer bastimeyer deleted the shell-completions branch September 26, 2021 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell tab completion support

2 participants