Skip to content

Commit

Permalink
Improve auto-completion
Browse files Browse the repository at this point in the history
- rename generate-aliases to bma-build
- the generator will now also generate avaliable bma functions
- update bash_completion to use the generated function list
- update README.md
  • Loading branch information
Justin Lam authored and mbailey committed Oct 30, 2019
1 parent 36c3cf3 commit eef7188
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ source ~/.bash-my-aws/bash_completion.sh

### Why the aliases?

<<<<<<< HEAD
`bash-my-aws` began as a collection of bash functions, sourced into your shell.
More recently, the default suggestion has been to load aliases that execute a
small wrapper script that loads the functions and executes the desired function.
Expand Down
46 changes: 46 additions & 0 deletions bin/bma-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
bma_path="$(cd "$(dirname "$0")/.." && pwd)"
aliases_destination="$bma_path/aliases"
funcs_destination="$bma_path/functions"

# extract functions in the subshells
pre_existing_functions=$(compgen -A function)

# load all the functions from bash-my-aws
for f in ~/.bash-my-aws/lib/*-functions; do source "$f"; done

# all functions in bma
inclusions=$(compgen -A function)

# empty the function list file
true > "$funcs_destination"

funcs=$(echo "${inclusions}" "${pre_existing_functions}" | tr ' ' '\n' | sort | uniq -u)
for fnc in $funcs; do
echo "$fnc" >> "$funcs_destination"
done;

# generate the aliases file
{
echo "# GENERATED ALIASES FOR BASH-MY-AWS"
echo "# to regenerate run: bin/$(basename "$0")"
echo ""
} > "$aliases_destination"

# functions to alias
exclusions=('region')

fncs_to_alias=$(echo "${inclusions}" "${pre_existing_functions}" "${exclusions}" | tr ' ' '\n' | sort | uniq -u)
for fnc in $fncs_to_alias; do
echo "alias $fnc='~/.bash-my-aws/bin/bma $fnc'" >> "$aliases_destination"
done;

# functions to clone
fncs_to_clone=('region')

# region() needs to be a function in order to let it set AWS_DEFAULT_REGION
# in the current shell
for fnc_name in $fncs_to_clone; do
function_body=$(type "$fnc_name" | tail -n +3)
printf "function %s() %s" "$fnc_name" "$function_body" >> "$aliases_destination"
done;
1 change: 1 addition & 0 deletions functions
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ asg-scaling-activities
asg-stack
asg-suspend
aws-account-alias
aws-account-each
aws-account-id
aws-panopticon
_bma_derive_params_from_stack_and_template
Expand Down

0 comments on commit eef7188

Please sign in to comment.