Skip to content

Bundle shell completion script(s) into installation package #4

@yermulnik

Description

@yermulnik

We are happy to answer your questions about the code or discuss technical ideas.

Please complete the following checklist (by adding [x]):

  • I have searched open and closed issues for duplicates
  • This isn't a feature request
  • This is not a report about my app not working as expected

Would it be possible to add CLI shell completion scripts into installation package?
I guess there some Python modules exist to automate this, else here's the simple Bash completion script that I just created locally:

Expand for script code
_protonvpn() {
	local cur prev
	cur=${COMP_WORDS[COMP_CWORD]}
	prev=${COMP_WORDS[COMP_CWORD - 1]}

	COMMANDS=($(compgen -W "$(protonvpn --help 2>&1 | sed -En '/^Commands:$/,/^$/{/^(Commands:)?$/!p}' | awk '{print $1}')" -- "$cur"))

	# Global commands
	if [[ $prev == protonvpn ]]; then
		COMPREPLY+=($(compgen -W "${COMMANDS[*]}" -- "$cur"))

		if [[ $cur == -* ]]; then
			COMPREPLY+=($(compgen -W "$(protonvpn --help 2>&1 | grep -Eo '[[:space:]]+(-{1,2}[a-zA-Z0-9-]+)')" -- "$cur"))
		fi

		return 0
	fi

	if [[ " ${COMMANDS[*]} " == *" $prev "* || $cur == -* ]]; then
		COMPREPLY+=($(compgen -W "$(protonvpn $prev --help 2>&1 | grep -Eo '[[:space:]]+(-{1,2}[a-zA-Z0-9-]+)')" -- "$cur"))
	fi
}
complete -F _protonvpn protonvpn

# vim: set filetype=bash shiftwidth=4 tabstop=4 noexpandtab autoindent:

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions