mbox

[6/6] autocompletion: add color commands

Message ID 1497003452-10190-6-git-send-email-jonatan.schlag@ipfire.org
State Dropped
Headers

Message

Jonatan Schlag June 9, 2017, 8:17 p.m. UTC
  Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 src/bash-completion/network | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)
  

Comments

Michael Tremer June 15, 2017, 7:12 a.m. UTC | #1
Hi,

On Fri, 2017-06-09 at 12:17 +0200, Jonatan Schlag wrote:
> Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
> ---
>  src/bash-completion/network | 30 ++++++++++++++++++++++++++----
>  1 file changed, 26 insertions(+), 4 deletions(-)
> 
> diff --git a/src/bash-completion/network b/src/bash-
> completion/network
> index 4b5e34d..321d0ff 100644
> --- a/src/bash-completion/network
> +++ b/src/bash-completion/network
> @@ -48,6 +48,17 @@ _network_complete_zones() {
>  	COMPREPLY=( $(compgen -W "$(network raw list-zones)" --
> "${cur}") )
>  }
>  

The function below should be prefixed with _network, because _color is
quite a common name and could be used by something else as well.

> +_color() {
> +	local words=( $@ )
> +
> +	local commands="set reset"
> +	local cmd="$(_network_find_on_cmdline "${commands}")"
> +	if [[ -z "${cmd}" ]]; then
> +		COMPREPLY=( $(compgen -W "${commands}" -- "${cur}")
> )
> +		return 0
> +	fi
> +}
> +
>  _network_device() {
>  	local words=( $@ )
>  
> @@ -78,7 +89,7 @@ _network_device_subcommand() {
>  		COMPREPLY=( $(compgen -W "${commands}" -- "${cur}")
> )
>  		return 0
>  	fi
> -			
> +
>  	case "${cmd}" in
>  		ussd)
>  			# TODO
> @@ -247,12 +258,20 @@ _network_port() {
>  _network_port_subcommand() {
>  	local words=( $@ )
>  
> -	local commands="create down edit identify remove status up"
> +	local commands="create down edit identify remove status up
> color"

Could you order the commands alphabetically?

>  	local cmd="$(_network_find_on_cmdline "${commands}")"
>  	if [[ -z "${cmd}" ]]; then
>  		COMPREPLY=( $(compgen -W "${commands}" -- "${cur}")
> )
>  		return 0
>  	fi
> +
> +	local args="${words[@]:1}"
> +	case "${cmd}" in
> +		color)
> +			_color ${args}
> +			;;
> +	esac
> +
>  }
>  
>  _network_route() {
> @@ -359,13 +378,13 @@ _network_zone_subcommand() {
>  
>  	local words=( $@ )
>  
> -	local commands="config disable down edit enable identify
> port rename status up"
> +	local commands="config disable down edit enable identify
> port rename status up color"

Same as above.

>  	local cmd="$(_network_find_on_cmdline "${commands}")"
>  	if [[ -z "${cmd}" ]]; then
>  		COMPREPLY=( $(compgen -W "${commands}" -- "${cur}")
> )
>  		return 0
>  	fi
> -			
> +
>  	local args="${words[@]:1}"
>  	case "${cmd}" in
>  		config)
> @@ -374,6 +393,9 @@ _network_zone_subcommand() {
>  		port)
>  			_network_zone_subcommand_port "${zone}"
> ${args}
>  			;;
> +		color)
> +			_color ${args}
> +			;;
>  	esac
>  }
> 

-Michael