Giter VIP home page Giter VIP logo

Comments (3)

rothgar avatar rothgar commented on August 28, 2024 2

Aliases would require manual shell completion files. It's possible to create your own completion files but not something that is supported by aws_completer

from awscli-aliases.

yermulnik avatar yermulnik commented on August 28, 2024

Any updates on this request?

from awscli-aliases.

yermulnik avatar yermulnik commented on August 28, 2024

So to add AWS CLI aliases to bash completions for aws one would need to create their own bash-completion function (e.g. _aws_cli_aliases), withing this function extract AWS CLI alias names like awk '$2 == "=" && $1 !~ /^#/ {print $1}' ~/.aws/cli/alias | sort and then add them to the completion stack like complete -C aws_completer -F _aws_cli_aliases aws.
This is a bit cumbersome and needs fiddling though... Here's what I came up with long ago (you would have to apologize the mess as it's a way far from ideal thing):
~/.bash_completion.d/aws.completion:

_aws_cli_aliases()
{
	COMPREPLY=()
	local cur=${COMP_WORDS[COMP_CWORD]}
	local prev=${COMP_WORDS[COMP_CWORD-1]}
	local cword=${COMP_WORDS[0]}

	if [[ $cur =~ ^- ]]; then
		if [[ $(aws version 2>&1 | awk -F"[/ .]" '{print $2}') -gt 1 ]]; then
			local all_global_opts=$(~/bin/aws-list-all-available-commands.py global_opts)
			COMPREPLY=($(compgen -W "$all_global_opts" -- $cur))
		else
			return 0
		fi
	elif [[ $prev == --profile ]]; then
		COMPREPLY=($(compgen -W "$(awk '/^\[/' ${AWS_SHARED_CREDENTIALS_FILE:=${HOME}/.aws/credentials} | tr -d '[]' | sort)" $cur))
	elif [[ $prev == --region ]]; then
		# aws ec2 describe-regions --query 'Regions[].RegionName[]' --output text | xargs -n1
		COMPREPLY=($(compgen -W "eu-north-1 ap-south-1 eu-west-3 eu-west-2 eu-west-1 ap-northeast-2 ap-northeast-1 sa-east-1 ca-central-1 ap-southeast-1 ap-southeast-2 eu-central-1 us-east-1 us-east-2 us-west-1 us-west-2" $cur))
	elif [[ $prev == --output ]]; then
		COMPREPLY=($(compgen -W "json yaml yaml-stream text table" $cur))
	else
		local cmds_hits
		local all_cmds=$(~/bin/aws-list-all-available-commands.py)
		local all_aliases=$(awk '$2 == "=" && $1 !~ /^#/ {print $1}' ~/.aws/cli/alias | sort)

		for cli_alias in $all_aliases; do
			if [[ $prev == $cli_alias ]]; then
				local all_global_opts=$(~/bin/aws-list-all-available-commands.py global_opts)
				COMPREPLY=($(compgen -W "$all_global_opts" -- $cur))
				return 0
			fi
		done

		for cli_cmd in ${COMP_WORDS[@]}; do
			for aws_cmd in $all_cmds $all_aliases; do
				if [[ $aws_cmd == $cli_cmd ]]; then
					((cmds_hits++))
					break 2
				fi
			done
		done
		[[ ! $cmds_hits ]] && COMPREPLY=($(compgen -W "$all_aliases" $cur))
	fi

	return 0
}
complete -C aws_completer -F _aws_cli_aliases aws

~/bin/aws-list-all-available-commands.py:

#!/usr/bin/env python
from sys import argv

if len(argv) > 1:
    if argv[1] == 'global_opts':
        import awscli.completer
        awscli.completer.complete("-", None)
else:
    import awscli.clidriver
    for cmd in awscli.clidriver.create_clidriver().create_help_command().command_table.keys():
        print(cmd)

Hope this helps someone...

from awscli-aliases.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.