Skip to content

feature - bash autocomplete #47

@mysiki

Description

@mysiki

hey, thanks for this tool really helpfull

I create script for bash autocompletion if you want to add it

#!/bin/bash

# Function to dynamically read AWS profiles from ~/.aws/config
_get_aws_profiles() {
  # Get profiles from ~/.aws/config by looking for lines that start with '[profile'
  if [[ -f "$HOME/.aws/config" ]]; then
    grep -E '^\[profile' "$HOME/.aws/config" | sed 's/\[profile //; s/\]//'
  fi
}

# Function to get AWS regions
_get_aws_regions() {
  # AWS regions 
  echo "us-east-1 us-east-2 us-west-1 us-west-2 eu-west-1 eu-west-2 eu-west-3 eu-central-1 eu-north-1 ap-south-1 ap-southeast-1 ap-southeast-2 ap-northeast-1 ap-northeast-2 sa-east-1 ca-central-1"
}

# Completion function for ec2-session
_ec2_session_complete() {
  local cur prev opts profiles regions
  cur="${COMP_WORDS[COMP_CWORD]}"
  prev="${COMP_WORDS[COMP_CWORD - 1]}"

  # Static options for completion (long arguments only)
  opts="--profile --region --verbose --debug --quiet --version --help"

  case "$prev" in
  --profile)
    # Dynamically complete profile names
    profiles=$(_get_aws_profiles)
    COMPREPLY=($(compgen -W "$profiles" -- "$cur"))
    return 0
    ;;
  --region)
    # Dynamically complete AWS region names
    regions=$(_get_aws_regions)
    COMPREPLY=($(compgen -W "$regions" -- "$cur"))
    return 0
    ;;
  *)
    # Complete static options (long options only)
    COMPREPLY=($(compgen -W "$opts" -- "$cur"))
    return 0
    ;;
  esac
}

# Register the completion function for ec2-session
complete -F _ec2_session_complete ec2-session

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions