forked from bash-my-aws/bash-my-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters