From eef71886a885473d693474f096f68be2f317b9af Mon Sep 17 00:00:00 2001 From: Justin Lam Date: Fri, 9 Aug 2019 13:08:27 +1000 Subject: [PATCH] Improve auto-completion - 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 --- README.md | 1 + bin/bma-build | 46 ++++++++++++++++++++++++++++++++++++++++++++++ functions | 1 + 3 files changed, 48 insertions(+) create mode 100755 bin/bma-build diff --git a/README.md b/README.md index 900208d1..da22b671 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/bin/bma-build b/bin/bma-build new file mode 100755 index 00000000..74800f5b --- /dev/null +++ b/bin/bma-build @@ -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; diff --git a/functions b/functions index f868a8ce..11b3edbb 100644 --- a/functions +++ b/functions @@ -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