├── zsh └── beamery │ ├── plugins │ ├── list_git_active_branch.zsh │ ├── clean_git_remote_branches.zsh │ ├── track_all_remote_git_branches.zsh │ ├── clean_git_branches.zsh │ ├── check_node_package_usage.zsh │ ├── clean_git_stash.zsh │ ├── audit_git_branches.zsh │ ├── link_node_modules.zsh │ ├── clean_npm_modules.zsh │ ├── update_git_branch.zsh │ ├── clean_git_local_branches.zsh │ ├── switch_git_branch.zsh │ ├── generate_npm_report.zsh │ └── switch_git_branch_and_update.zsh │ ├── beamery.plugin.zsh │ └── pluginsInterface.zsh ├── beamery ├── plugins │ ├── list_git_active_branch.sh │ ├── check_node_package_usage.sh │ ├── clean_git_remote_branches.sh │ ├── clean_git_branches.sh │ ├── track_all_remote_git_branches.sh │ ├── clean_git_stash.sh │ ├── audit_git_branches.sh │ ├── link_node_modules.sh │ ├── update_git_branch.sh │ ├── clean_git_local_branches.sh │ ├── clean_npm_modules.sh │ ├── switch_git_branch.sh │ ├── generate_npm_report.sh │ └── switch_git_branch_and_update.sh ├── beamery.sh └── pluginsInterface.sh ├── bash-it ├── beamery │ ├── plugins │ │ ├── list_git_active_branch.bash │ │ ├── check_node_package_usage.bash │ │ ├── clean_git_remote_branches.bash │ │ ├── clean_git_branches.bash │ │ ├── clean_git_stash.bash │ │ ├── track_all_remote_git_branches.bash │ │ ├── audit_git_branches.bash │ │ ├── link_node_modules.bash │ │ ├── clean_npm_modules.bash │ │ ├── update_git_branch.bash │ │ ├── clean_git_local_branches.bash │ │ ├── switch_git_branch.bash │ │ ├── generate_npm_report.bash │ │ └── switch_git_branch_and_update.bash │ └── pluginsInterface.bash ├── beamery.completion.bash └── beamery.plugin.bash ├── LICENSE.md ├── install.sh └── README.md /zsh/beamery/plugins/list_git_active_branch.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.oh-my-zsh/plugins/beamery/pluginsInterface.zsh" 5 | 6 | # List the current branches on the repos 7 | # This is useful to know which branches are flipped on which repos 8 | 9 | list_git_active_branch() { 10 | execute -g $@ printf "'Branch: ${YELLOW}' && git branch | grep '^\*' | cut -d' ' -f2 && printf '${NC}'" 11 | } 12 | -------------------------------------------------------------------------------- /beamery/plugins/list_git_active_branch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.beamery/beamery/pluginsInterface.sh" 5 | 6 | # list_git_active_branch 7 | # List the current branches on the repos 8 | # This is useful to know which branches are flipped on which repos 9 | 10 | list_git_active_branch() { 11 | execute -g $@ printf "'\e[1A\e[70CBranch: ${YELLOW}' && git branch | grep '^\*' | cut -d' ' -f2 && printf '${NC}'" 12 | } 13 | -------------------------------------------------------------------------------- /zsh/beamery/plugins/clean_git_remote_branches.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.oh-my-zsh/plugins/beamery/pluginsInterface.zsh" 5 | 6 | # Clean remote branches that have been merged into master and delete them from remotes as well 7 | 8 | clean_git_remote_branches() { 9 | execute -g $@ "echo""; git branch -r --merged | egrep -v '(^\*|master|development)' | sed 's/origin\///g'| xargs -n 1 git push --delete origin; echo ''" 10 | } 11 | -------------------------------------------------------------------------------- /zsh/beamery/plugins/track_all_remote_git_branches.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.oh-my-zsh/plugins/beamery/pluginsInterface.zsh" 5 | 6 | # Track all remote branches that are not being tracked locally 7 | 8 | track_all_remote_git_branches() { 9 | execute -g $@ "git branch -r | grep -v '\->' | while read remote; do git branch --track ${remote#origin/} $remote > /dev/null; done;" 10 | echo "--> All remote branches tracked" 11 | } 12 | -------------------------------------------------------------------------------- /bash-it/beamery/plugins/list_git_active_branch.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash" 5 | 6 | # list_git_active_branch 7 | # List the current branches on the repos 8 | # This is useful to know which branches are flipped on which repos 9 | 10 | list_git_active_branch() { 11 | execute -g $@ printf "'\e[1A\e[70CBranch: ${YELLOW}' && git branch | grep '^\*' | cut -d' ' -f2 && printf '${NC}'" 12 | } 13 | -------------------------------------------------------------------------------- /beamery/plugins/check_node_package_usage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.beamery/beamery/pluginsInterface.sh" 5 | 6 | # check_node_package_usage 7 | # Check the places a certain npm package is used across all the repos 8 | 9 | check_node_package_usage() { 10 | 11 | execute -n "grep -sw $1 ./package.json >/dev/null && printf '\e[1A\e[40C' && grep -sw '\"$1\":' ./package.json && echo "" || printf '\e[1A\e[K'" 12 | echo "" 13 | } 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /beamery/plugins/clean_git_remote_branches.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.beamery/beamery/pluginsInterface.sh" 5 | 6 | # clean_git_remote_branches 7 | # Clean remote branches that have been merged into master and delete them from remotes as well 8 | 9 | clean_git_remote_branches() { 10 | execute -g $@ "echo""; git branch -r --merged | egrep -v '(^\*|master|development)' | sed 's/origin\///g'| xargs -n 1 git push --delete origin; echo ''" 11 | } 12 | -------------------------------------------------------------------------------- /zsh/beamery/plugins/clean_git_branches.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.oh-my-zsh/plugins/beamery/pluginsInterface.zsh" 5 | 6 | # Total cleaning on branches by first performing deletion of remote branches that have been merged into master 7 | # Second step will be to execute deletio of local branches that are not on remote/merged into master 8 | 9 | clean_git_branches() { 10 | clean_git_remote_branches $1 11 | clean_git_local_branches $1 12 | } 13 | -------------------------------------------------------------------------------- /beamery/plugins/clean_git_branches.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.beamery/beamery/pluginsInterface.sh" 5 | 6 | # clean_git_branches 7 | # Total cleaning on branches by first performing deletion of remote branches that have been merged into master 8 | # Second step will be to execute deletio of local branches that are not on remote/merged into master 9 | 10 | clean_git_branches() { 11 | clean_git_remote_branches $1 12 | clean_git_local_branches $1 13 | } 14 | -------------------------------------------------------------------------------- /beamery/plugins/track_all_remote_git_branches.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.beamery/beamery/pluginsInterface.sh" 5 | 6 | # track_all_remote_git_branches 7 | # Track all remote branches that are not being tracked locally 8 | 9 | track_all_remote_git_branches() { 10 | execute -g $@ "git branch -r | grep -v '\->' | while read remote; do git branch --track ${remote#origin/} $remote > /dev/null; done;" 11 | echo "--> All remote branches tracked" 12 | } 13 | 14 | -------------------------------------------------------------------------------- /bash-it/beamery/plugins/check_node_package_usage.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash" 5 | 6 | # check_node_package_usage 7 | # Check the places a certain npm package is used across all the repos 8 | 9 | check_node_package_usage() { 10 | 11 | execute -n "grep -sw $1 ./package.json >/dev/null && printf '\e[1A\e[40C' && grep -sw '\"$1\":' ./package.json && echo "" || printf '\e[1A\e[K'" 12 | echo "" 13 | } 14 | 15 | -------------------------------------------------------------------------------- /bash-it/beamery/plugins/clean_git_remote_branches.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash" 5 | 6 | # clean_git_remote_branches 7 | # Clean remote branches that have been merged into master and delete them from remotes as well 8 | 9 | clean_git_remote_branches() { 10 | execute -g $@ "echo""; git branch -r --merged | egrep -v '(^\*|master|development)' | sed 's/origin\///g'| xargs -n 1 git push --delete origin; echo ''" 11 | } 12 | -------------------------------------------------------------------------------- /bash-it/beamery/plugins/clean_git_branches.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash" 5 | 6 | # clean_git_branches 7 | # Total cleaning on branches by first performing deletion of remote branches that have been merged into master 8 | # Second step will be to execute deletio of local branches that are not on remote/merged into master 9 | 10 | clean_git_branches() { 11 | clean_git_remote_branches $1 12 | clean_git_local_branches $1 13 | } 14 | -------------------------------------------------------------------------------- /zsh/beamery/plugins/check_node_package_usage.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.oh-my-zsh/plugins/beamery/pluginsInterface.zsh" 5 | 6 | # check_node_package_usage 7 | # Check the places a certain npm package is used across all the repos 8 | 9 | check_node_package_usage() { 10 | 11 | find . -maxdepth 1 -type d \( ! -name . \) | while read -r SUBFOLDER; do [[ -f "`pwd`/$SUBFOLDER/package.json" ]] && cat "`pwd`/$SUBFOLDER/package.json" | grep -sw "\"$1\":" && echo "$SUBFOLDER"; done; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /zsh/beamery/plugins/clean_git_stash.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.oh-my-zsh/plugins/beamery/pluginsInterface.zsh" 5 | 6 | # Clean any stashed commits 7 | 8 | clean_git_stash() { 9 | 10 | printf "${RED}Please note that this will clear any stashes you have saved${NC}\n" 11 | read -q "REPLY?Are you sure you want to proceed ? [Y/N] "; 12 | 13 | if [[ $REPLY =~ ^[Yy]$ ]]; then 14 | execute -g $@ "echo ''; git stash clear && echo '--> done'" 15 | fi 16 | echo ""; 17 | } 18 | -------------------------------------------------------------------------------- /beamery/plugins/clean_git_stash.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.beamery/beamery/pluginsInterface.sh" 5 | 6 | # clean_git_stash 7 | # Clean any stashed commits 8 | 9 | clean_git_stash() { 10 | 11 | printf "${RED}Please note that this will clear any stashes you have saved${NC}\n" 12 | read -p "Are you sure you want to proceed ? [Y/N] " -n 1; 13 | 14 | if [[ $REPLY =~ ^[Yy]$ ]]; then 15 | execute -g $@ "echo ''; git stash clear && echo '--> done'" 16 | fi 17 | echo ""; 18 | } 19 | -------------------------------------------------------------------------------- /bash-it/beamery/plugins/clean_git_stash.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash" 5 | 6 | # clean_git_stash 7 | # Clean any stashed commits 8 | 9 | clean_git_stash() { 10 | 11 | printf "${RED}Please note that this will clear any stashes you have saved${NC}\n" 12 | read -p "Are you sure you want to proceed ? [Y/N] " -n 1; 13 | 14 | if [[ $REPLY =~ ^[Yy]$ ]]; then 15 | execute -g $@ "echo ''; git stash clear && echo '--> done'" 16 | fi 17 | echo ""; 18 | } 19 | -------------------------------------------------------------------------------- /zsh/beamery/plugins/audit_git_branches.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.oh-my-zsh/plugins/beamery/pluginsInterface.zsh" 5 | 6 | # List all the branches of a .git repository sorted by date creation 7 | # This is useful to identify dead branches 8 | 9 | audit_git_branches() { 10 | execute -g $@ "echo ""; git branch -vv; echo ''"; 11 | 12 | printf "${YELLOW}\nHistorical Branches Data:\n${NC}"; 13 | execute -g $@ "echo ""; git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/remotes; echo "";" 14 | } 15 | -------------------------------------------------------------------------------- /beamery/plugins/audit_git_branches.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.beamery/beamery/pluginsInterface.sh" 5 | 6 | # audit_git_branches 7 | # List all the branches of a .git repository sorted by date creation 8 | # This is useful to identify dead branches 9 | 10 | audit_git_branches() { 11 | execute -g $@ "echo ""; git branch -vv; echo ''"; 12 | 13 | printf "${YELLOW}\nHistorical Branches Data:\n${NC}"; 14 | execute -g $@ "echo ""; git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/remotes; echo "";" 15 | } 16 | -------------------------------------------------------------------------------- /bash-it/beamery/plugins/track_all_remote_git_branches.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash" 5 | 6 | # track_all_remote_git_branches 7 | # Track all remote branches that are not being tracked locally 8 | # This is useful when we want to clean out local branches and need to fetch all remote branches 9 | 10 | track_all_remote_git_branches() { 11 | execute -g $@ "git branch -r | grep -v '\->' | while read remote; do git branch --track ${remote#origin/} $remote > /dev/null; done;" 12 | echo "--> All remote branches tracked" 13 | } 14 | -------------------------------------------------------------------------------- /bash-it/beamery/plugins/audit_git_branches.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash" 5 | 6 | # audit_git_branches 7 | # List all the branches of a .git repository sorted by date creation 8 | # This is useful to identify dead branches 9 | 10 | audit_git_branches() { 11 | execute -g $@ "echo ""; git branch -vv; echo ''"; 12 | 13 | printf "${YELLOW}\nHistorical Branches Data:\n${NC}"; 14 | execute -g $@ "echo ""; git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/remotes; echo "";" 15 | } 16 | -------------------------------------------------------------------------------- /zsh/beamery/plugins/link_node_modules.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.oh-my-zsh/plugins/beamery/pluginsInterface.zsh" 5 | 6 | # Remove all node_modules from all the repos and run zelda to link and download all 7 | 8 | link_node_modules() { 9 | 10 | printf "${RED}Please note that this will remove all node_modules from all repos\n${NC}" 11 | read -q "REPLY?Do you want to clean node_modules before linking? [Y/N] "; 12 | if [[ $REPLY =~ ^[yY]$ ]]; then 13 | execute -n $@ "echo ' ---> removing node_modules' && rm -rf node_modules && zelda ../" 14 | else 15 | execute -n $@ "zelda ../" 16 | fi 17 | } 18 | -------------------------------------------------------------------------------- /beamery/plugins/link_node_modules.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.beamery/beamery/pluginsInterface.sh" 5 | 6 | # link_node_modules 7 | # Remove all node_modules from all the repos and run zelda to link and download all 8 | 9 | link_node_modules() { 10 | 11 | printf "${RED}Please note that this will remove all node_modules from all repos\n${NC}" 12 | read -p "Do you want to clean node_modules before linking? [Y/N] " -n 1; 13 | if [[ $REPLY =~ ^[yY]$ ]]; then 14 | execute -n $@ "echo ' ---> removing node_modules' && rm -rf node_modules && zelda ../" 15 | else 16 | execute -n $@ "zelda ../" 17 | fi 18 | } 19 | -------------------------------------------------------------------------------- /bash-it/beamery/plugins/link_node_modules.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash" 5 | 6 | # link_node_modules 7 | # Remove all node_modules from all the repos and run zelda to link and download all 8 | 9 | link_node_modules() { 10 | 11 | read -p "Do you want to clean node_modules before linking? [Y/N] " -n 1; 12 | printf "${RED}Please note that this will remove all node_modules from all repos\n${NC}" 13 | if [[ $REPLY =~ ^[yY]$ ]]; then 14 | execute -n $@ "echo ' ---> removing node_modules' && rm -rf node_modules && zelda ../" 15 | else 16 | execute -n $@ "zelda ../" 17 | fi 18 | } 19 | -------------------------------------------------------------------------------- /zsh/beamery/plugins/clean_npm_modules.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.oh-my-zsh/plugins/beamery/pluginsInterface.zsh" 5 | 6 | # Clean unused NPM modules from each repo 7 | # The function will check if npm-clean is installed and install it otherwise 8 | 9 | clean_npm_modules() { 10 | 11 | if [[ $@ == *'-s'* ]]; then 12 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 13 | else 14 | if command_exists npm-clean ; then 15 | execute -n $@ "npm-clean >> ../npm-clean-report.txt" 16 | else 17 | printf 'npm-check module was not found. Installing now:'; 18 | npm install -g npm-clean 19 | execute -n $@ "npm-clean >> ../npm-clean-report.txt" 20 | fi 21 | fi; 22 | } 23 | -------------------------------------------------------------------------------- /zsh/beamery/plugins/update_git_branch.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.oh-my-zsh/plugins/beamery/pluginsInterface.zsh" 5 | 6 | # Update .git branches from the latest remote origin 7 | # The command accepts two optional argument which is the new branch to checkout 8 | # If no argument was passed then the command will default and switch all repos to master 9 | # If a second argument is passed then it will from that remote, if not it will default to origin 10 | # Default paramteres: git pull origin master 11 | 12 | update_git_branch() { 13 | 14 | if [[ $@ == *'-s'* ]]; then 15 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 16 | else 17 | execute -g "echo''; git pull ${2:-origin} ${1:-master}; echo''" 18 | fi; 19 | } 20 | -------------------------------------------------------------------------------- /beamery/plugins/update_git_branch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.beamery/beamery/pluginsInterface.sh" 5 | 6 | # update_git_branch 7 | # Update .git branches from the latest remote origin 8 | # The command accepts two optional argument which is the new branch to checkout 9 | # If no argument was passed then the command will default and switch all repos to master 10 | # If a second argument is passed then it will from that remote, if not it will default to origin 11 | # Default paramteres: git pull origin master 12 | 13 | update_git_branch() { 14 | 15 | if [[ $@ == *'-s'* ]]; then 16 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 17 | else 18 | execute -g "echo''; git pull ${2:-origin} ${1:-master}; echo''" 19 | fi; 20 | } 21 | -------------------------------------------------------------------------------- /bash-it/beamery/plugins/clean_npm_modules.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash" 5 | 6 | # clean_npm_modules 7 | # Clean unused NPM modules from each repo 8 | # The function will check if npm-clean is installed and install it otherwise 9 | 10 | clean_npm_modules() { 11 | 12 | if [[ $@ == *'-s'* ]]; then 13 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 14 | else 15 | if command_exists npm-clean ; then 16 | execute -n $@ "npm-clean >> ../npm-clean-report.txt" 17 | else 18 | printf 'npm-check module was not found. Installing now:'; 19 | npm install -g npm-clean 20 | execute -n $@ "npm-clean >> ../npm-clean-report.txt" 21 | fi 22 | fi; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /bash-it/beamery/plugins/update_git_branch.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash" 5 | 6 | # update_git_branch 7 | # Update .git branches from the latest remote origin 8 | # The command accepts two optional argument which is the new branch to checkout 9 | # If no argument was passed then the command will default and switch all repos to master 10 | # If a second argument is passed then it will from that remote, if not it will default to origin 11 | # Default paramteres: git pull origin master 12 | 13 | update_git_branch() { 14 | 15 | if [[ $@ == *'-s'* ]]; then 16 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 17 | else 18 | execute -g "echo''; git pull ${2:-origin} ${1:-master}; echo''" 19 | fi; 20 | } 21 | -------------------------------------------------------------------------------- /bash-it/beamery.completion.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | _beamery_comp() 4 | { 5 | local cur prev opts prevprev 6 | COMPREPLY=() 7 | cur="${COMP_WORDS[COMP_CWORD]}" 8 | prev="${COMP_WORDS[COMP_CWORD-1]}" 9 | chose_opt="${COMP_WORDS[1]}" 10 | file_type="${COMP_WORDS[2]}" 11 | opts="execute update" 12 | if [ -d "${HOME}/.bash_it/plugins/available/beamery/plugins" ]; then 13 | for config_file in ${HOME}/.bash_it/plugins/available/beamery/plugins/*.bash 14 | do 15 | if [ -e "${config_file}" ]; then 16 | opts+=" `basename $config_file .bash`" 17 | fi 18 | done 19 | fi 20 | case "${chose_opt}" in 21 | help) 22 | local help_args="$(echo "${opts}" | cut -d " " -f2-)" 23 | COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) ) 24 | return 0 25 | ;; 26 | esac 27 | COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) 28 | return 0 29 | } 30 | 31 | complete -F _beamery_comp beamery 32 | -------------------------------------------------------------------------------- /zsh/beamery/plugins/clean_git_local_branches.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.oh-my-zsh/plugins/beamery/pluginsInterface.zsh" 5 | 6 | # Clean any local branches that have been deleted on remote 7 | 8 | clean_git_local_branches() { 9 | 10 | # Check if gawk is installed which is not by default in mac systems 11 | if ! type gawk &> /dev/null ; then 12 | if [[ "$OSTYPE" == "darwin"* ]]; then 13 | printf "The required package ${YELLOW}gawk${NC} was not found .. installing now\n" 14 | brew install gawk 15 | fi 16 | fi 17 | 18 | execute -g $@ "echo""; git fetch --all && git remote prune origin && git gc --prune=now; echo''"; 19 | 20 | if [[ `git branch -vv | grep ': gone]'` ]]; then 21 | printf "\n${YELLOW}Making sure that all 'gone' branches are also removed ..\n\n${NC}" 22 | execute -g $@ "git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -d" 23 | fi 24 | 25 | } 26 | -------------------------------------------------------------------------------- /beamery/plugins/clean_git_local_branches.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.beamery/beamery/pluginsInterface.sh" 5 | 6 | # clean_git_local_branches 7 | # Clean any local branches that have been deleted on remote 8 | 9 | 10 | clean_git_local_branches() { 11 | 12 | # Check if gawk is installed which is not by default in mac systems 13 | if ! type gawk &> /dev/null ; then 14 | if [[ "$OSTYPE" == "darwin"* ]]; then 15 | printf "The required package ${YELLOW}gawk${NC} was not found .. installing now\n" 16 | brew install gawk 17 | fi 18 | fi 19 | 20 | execute -g $@ "echo""; git fetch --all && git remote prune origin && git gc --prune=now; echo''"; 21 | 22 | if [[ `git branch -vv | grep ': gone]'` ]]; then 23 | printf "\n${YELLOW}Making sure that all 'gone' branches are also removed ..\n\n${NC}" 24 | execute -g $@ "git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -d" 25 | fi 26 | 27 | } 28 | 29 | -------------------------------------------------------------------------------- /bash-it/beamery/plugins/clean_git_local_branches.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash" 5 | 6 | # clean_git_local_branches 7 | # Clean any local branches that have been deleted on remote 8 | 9 | clean_git_local_branches() { 10 | 11 | # Check if gawk is installed which is not by default in mac systems 12 | if ! type gawk &> /dev/null ; then 13 | if [[ "$OSTYPE" == "darwin"* ]]; then 14 | printf "The required package ${YELLOW}gawk${NC} was not found .. installing now\n" 15 | brew install gawk 16 | fi 17 | fi 18 | 19 | execute -g $@ "echo""; git fetch --all && git remote prune origin && git gc --prune=now; echo''"; 20 | 21 | if [[ `git branch -vv | grep ': gone]'` ]]; then 22 | printf "\n${YELLOW}Making sure that all 'gone' branches are also removed ..\n\n${NC}" 23 | execute -g $@ "git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -d" 24 | fi 25 | 26 | } 27 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Beamery Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /beamery/plugins/clean_npm_modules.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.beamery/beamery/pluginsInterface.sh" 5 | 6 | # clean_npm_modules 7 | # Clean unused NPM modules from each repo 8 | # The function will check if npm-clean is installed and install it otherwise 9 | 10 | clean_npm_modules() { 11 | 12 | check_npm_report() { 13 | if [[ -f "npm-report.txt" ]]; then 14 | read -p "We have detected that an npm-clean-report already exists. Would you like to clear that out before ? [Y/N] " -n 1; 15 | if [[ $REPLY =~ ^[Yy]$ ]]; then 16 | rm -rf "npm-clean-report.txt" 17 | echo "" 18 | fi; 19 | fi; 20 | } 21 | 22 | if [[ $@ == *'-s'* ]]; then 23 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 24 | else 25 | if command_exists npm-clean ; then 26 | check_npm_report 27 | execute -n 'echo "Cleaning NPM modules in package.json"; echo [REPOSITORY] `basename $PWD` >> ../npm-clean-report.txt; npm-clean >> ../npm-clean-report.txt' 28 | else 29 | printf 'npm-check module was not found. Installing now:'; 30 | npm install -g npm-clean 31 | check_npm_report 32 | execute -n 'echo "Cleaning NPM modules in package.json"; echo [REPOSITORY] `basename $PWD` >> ../npm-clean-report.txt; npm-clean >> ../npm-clean-report.txt' 33 | fi 34 | fi; 35 | } 36 | -------------------------------------------------------------------------------- /zsh/beamery/plugins/switch_git_branch.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.oh-my-zsh/plugins/beamery/pluginsInterface.zsh" 5 | 6 | # Switch the branches of .git repos into a specific branch 7 | # The command accepts an optional argument which is the new branch to checkout 8 | # If no argument was passed then the command will default and switch all repos to master 9 | # Default paramteres: git checkout master 10 | 11 | switch_git_branch() { 12 | 13 | BRANCH=${1:-master} 14 | 15 | if [[ $@ == *'-s'* ]]; then 16 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 17 | else 18 | printf "${RED}Please note that this will stash any changes made in the repos and flip the current branch${NC}\n" 19 | read -q "REPLY?Are you sure you want to proceed? [Y/N] "; 20 | if [[ $REPLY =~ ^[Yy]$ ]]; then 21 | if ! [[ $BRANCH =~ ^(master|development)$ ]]; then 22 | printf "\nYou are switching to a non-default branch ... fetching first\n" 23 | execute -g "echo''; git fetch; git branch | grep -w $BRANCH > /dev/null && git stash && git checkout $BRANCH || echo 'This branch does not exist in this repo'; echo''" 24 | else 25 | execute -g "echo''; git branch | grep -w $BRANCH > /dev/null && git stash && git checkout $BRANCH || echo 'This branch does not exist in this repo'; echo''" 26 | fi 27 | fi; 28 | fi; 29 | } 30 | -------------------------------------------------------------------------------- /beamery/plugins/switch_git_branch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.beamery/beamery/pluginsInterface.sh" 5 | 6 | # switch_git_branch 7 | # Switch the branches of .git repos into a specific branch 8 | # The command accepts an optional argument which is the new branch to checkout 9 | # If no argument was passed then the command will default and switch all repos to master 10 | # Default paramteres: git checkout master 11 | 12 | switch_git_branch() { 13 | 14 | BRANCH=${1:-master} 15 | 16 | if [[ $@ == *'-s'* ]]; then 17 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 18 | else 19 | printf "${RED}Please note that this will stash any changes made in the repos and flip the current branch${NC}\n" 20 | read -p "Are you sure you want to proceed? [Y/N] " -n 1; 21 | if [[ $REPLY =~ ^[Yy]$ ]]; then 22 | if ! [[ $BRANCH =~ ^(master|development)$ ]]; then 23 | printf "\nYou are switching to a non-default branch ... fetching first\n" 24 | execute -g "echo''; git fetch; git branch | grep -w $BRANCH > /dev/null && git stash && git checkout $BRANCH || echo 'This branch does not exist in this repo'; echo''" 25 | else 26 | execute -g "echo''; git branch | grep -w $BRANCH > /dev/null && git stash && git checkout $BRANCH || echo 'This branch does not exist in this repo'; echo''" 27 | fi 28 | fi; 29 | fi; 30 | } 31 | -------------------------------------------------------------------------------- /bash-it/beamery/plugins/switch_git_branch.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash" 5 | 6 | # switch_git_branch 7 | # Switch the branches of .git repos into a specific branch 8 | # The command accepts an optional argument which is the new branch to checkout 9 | # If no argument was passed then the command will default and switch all repos to master 10 | # Default paramteres: git checkout master 11 | 12 | switch_git_branch() { 13 | 14 | BRANCH=${1:-master} 15 | 16 | if [[ $@ == *'-s'* ]]; then 17 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 18 | else 19 | printf "${RED}Please note that this will stash any changes made in the repos and flip the current branch${NC}\n" 20 | read -p "Are you sure you want to proceed? [Y/N] " -n 1; 21 | if [[ $REPLY =~ ^[Yy]$ ]]; then 22 | if ! [[ $BRANCH =~ ^(master|development)$ ]]; then 23 | printf "\nYou are switching to a non-default branch ... fetching first\n" 24 | execute -g "echo''; git fetch; git branch | grep -w $BRANCH > /dev/null && git stash && git checkout $BRANCH || echo 'This branch does not exist in this repo'; echo''" 25 | else 26 | execute -g "echo''; git branch | grep -w $BRANCH > /dev/null && git stash && git checkout $BRANCH || echo 'This branch does not exist in this repo'; echo''" 27 | fi 28 | fi; 29 | fi; 30 | } 31 | -------------------------------------------------------------------------------- /zsh/beamery/plugins/generate_npm_report.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.oh-my-zsh/plugins/beamery/pluginsInterface.zsh" 5 | 6 | # Generate NPM report using the npm-check module to inspect the state of our npm modules 7 | # The function will check if npm-check is installed and install it otherwise 8 | # The report will be generated in the root directory and will be called npm-report.txt 9 | 10 | generate_npm_report() { 11 | 12 | check_npm_report() { 13 | if [[ -f "npm-report.txt" ]]; then 14 | read -q "REPLY?We have detected that an npm-report already exists. Would you like to clear that out before ? [Y/N] "; 15 | if [[ $REPLY =~ ^[Yy]$ ]]; then 16 | rm -rf "npm-report.txt" 17 | echo "" 18 | fi; 19 | fi; 20 | } 21 | 22 | if [[ $@ == *'-s'* ]]; then 23 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 24 | else 25 | if command_exists npm-check ; then 26 | check_npm_report 27 | execute -n 'echo "Checking NPM modules in package.json"; echo [REPOSITORY] `basename $PWD` >> ../npm-report.txt; npm-check >> ../npm-report.txt' 28 | else 29 | printf 'npm-check module was not found. Installing now:'; 30 | npm install -g npm-check 31 | check_npm_report 32 | execute -n 'echo "Checking NPM modules in package.json"; echo [REPOSITORY] `basename $PWD` >> ../npm-report.txt; npm-check >> ../npm-report.txt' 33 | fi 34 | fi; 35 | } 36 | -------------------------------------------------------------------------------- /beamery/plugins/generate_npm_report.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.beamery/beamery/pluginsInterface.sh" 5 | 6 | # generate_npm_report 7 | # Generate NPM report using the npm-check module to inspect the state of our npm modules 8 | # The function will check if npm-check is installed and install it otherwise 9 | # The report will be generated in the root directory and will be called npm-report.txt 10 | 11 | generate_npm_report() { 12 | 13 | check_npm_report() { 14 | if [[ -f "npm-report.txt" ]]; then 15 | read -p "We have detected that an npm-report already exists. Would you like to clear that out before ? [Y/N] " -n 1; 16 | if [[ $REPLY =~ ^[Yy]$ ]]; then 17 | rm -rf "npm-report.txt" 18 | echo "" 19 | fi; 20 | fi; 21 | } 22 | 23 | if [[ $@ == *'-s'* ]]; then 24 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 25 | else 26 | if command_exists npm-check ; then 27 | check_npm_report 28 | execute -n 'echo "Checking NPM modules in package.json"; echo [REPOSITORY] `basename $PWD` >> ../npm-report.txt; npm-check >> ../npm-report.txt' 29 | else 30 | printf 'npm-check module was not found. Installing now:'; 31 | npm install -g npm-check 32 | check_npm_report 33 | execute -n 'echo "Checking NPM modules in package.json"; echo [REPOSITORY] `basename $PWD` >> ../npm-report.txt; npm-check >> ../npm-report.txt' 34 | fi 35 | fi; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /bash-it/beamery/plugins/generate_npm_report.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash" 5 | 6 | # generate_npm_report 7 | # Generate NPM report using the npm-check module to inspect the state of our npm modules 8 | # The function will check if npm-check is installed and install it otherwise 9 | # The report will be generated in the root directory and will be called npm-report.txt 10 | 11 | generate_npm_report() { 12 | 13 | check_npm_report() { 14 | if [[ -f "npm-report.txt" ]]; then 15 | read -p "We have detected that an npm-report already exists. Would you like to clear that out before ? [Y/N] " -n 1; 16 | if [[ $REPLY =~ ^[Yy]$ ]]; then 17 | rm -rf "npm-report.txt" 18 | echo "" 19 | fi; 20 | fi; 21 | } 22 | 23 | if [[ $@ == *'-s'* ]]; then 24 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 25 | else 26 | if command_exists npm-check ; then 27 | check_npm_report 28 | execute -n 'echo "Checking NPM modules in package.json"; echo [REPOSITORY] `basename $PWD` >> ../npm-report.txt; npm-check >> ../npm-report.txt' 29 | else 30 | printf 'npm-check module was not found. Installing now:'; 31 | npm install -g npm-check 32 | check_npm_report 33 | execute -n 'echo "Checking NPM modules in package.json"; echo [REPOSITORY] `basename $PWD` >> ../npm-report.txt; npm-check >> ../npm-report.txt' 34 | fi 35 | fi; 36 | } 37 | -------------------------------------------------------------------------------- /zsh/beamery/plugins/switch_git_branch_and_update.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.oh-my-zsh/plugins/beamery/pluginsInterface.zsh" 5 | 6 | # Switch the branches of .git repos into a specific branch and update from the latest remote origin 7 | # The command accepts two optional argument which is the new branch to checkout 8 | # If no argument was passed then the command will default and switch all repos to master 9 | # If a second argument is passed then it will from that remote, if not it will default to origin 10 | # Default paramteres: git checkout master; git pull origin master 11 | 12 | switch_git_branch_and_update() { 13 | 14 | if [[ $@ == *'-s'* ]]; then 15 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 16 | else 17 | # if a second parameter is defined as a remote it will be used, if not then it will pull from origin 18 | REMOTE=${1:-origin} 19 | BRANCH=${2:-master} 20 | 21 | printf "${RED}Please note that this will stash any changes made in the repos and flip the current branch${NC}\n" 22 | read -q "REPLY?Are you sure you want to proceed? [Y/N] "; 23 | echo "" 24 | 25 | if [[ $REPLY =~ ^[Yy]$ ]]; then 26 | if ! [[ $BRANCH =~ ^(master|development)$ ]]; then 27 | printf "\nYou are switching to a non-default branch ... will fetch repositories first\n" 28 | # Since this function already accepts params passed 29 | # We need to check if any of the params passed is the -s which indicates this should run on a single folder 30 | execute -g "echo ''; git fetch; git branch | grep -w $BRANCH > /dev/null && git stash && git checkout $BRANCH && git pull $REMOTE $BRANCH || echo 'This branch does not exist in this repo'; echo''" 31 | else 32 | execute -g "echo ''; git branch | grep -w $BRANCH > /dev/null && git stash && git checkout $BRANCH && git pull $REMOTE $BRANCH || echo 'This branch does not exist in this repo'; echo''" 33 | fi 34 | fi; 35 | fi; 36 | } 37 | -------------------------------------------------------------------------------- /beamery/plugins/switch_git_branch_and_update.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.beamery/beamery/pluginsInterface.sh" 5 | 6 | # switch_git_branch_and_update 7 | # Switch the branches of .git repos into a specific branch and update from the latest remote origin 8 | # The command accepts two optional argument which is the new branch to checkout 9 | # If no argument was passed then the command will default and switch all repos to master 10 | # If a second argument is passed then it will from that remote, if not it will default to origin 11 | # Default paramteres: git checkout master; git pull origin master 12 | 13 | switch_git_branch_and_update() { 14 | 15 | if [[ $@ == *'-s'* ]]; then 16 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 17 | else 18 | # if a second parameter is defined as a remote it will be used, if not then it will pull from origin 19 | REMOTE=${1:-origin} 20 | BRANCH=${2:-master} 21 | 22 | printf "${RED}Please note that this will stash any changes made in the repos and flip the current branch${NC}\n" 23 | read -p "Are you sure you want to proceed? [Y/N] " -n 1; 24 | echo "" 25 | 26 | if [[ $REPLY =~ ^[Yy]$ ]]; then 27 | if ! [[ $BRANCH =~ ^(master|development)$ ]]; then 28 | printf "\nYou are switching to a non-default branch ... will fetch repositories first\n" 29 | # Since this function already accepts params passed 30 | # We need to check if any of the params passed is the -s which indicates this should run on a single folder 31 | execute -g "echo ''; git fetch; git branch | grep -w $BRANCH > /dev/null && git stash && git checkout $BRANCH && git pull $REMOTE $BRANCH || echo 'This branch does not exist in this repo'; echo''" 32 | else 33 | execute -g "echo ''; git branch | grep -w $BRANCH > /dev/null && git stash && git checkout $BRANCH && git pull $REMOTE $BRANCH || echo 'This branch does not exist in this repo'; echo''" 34 | fi 35 | fi; 36 | fi; 37 | } 38 | -------------------------------------------------------------------------------- /bash-it/beamery/plugins/switch_git_branch_and_update.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Load the main plugins "interface" 4 | source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash" 5 | 6 | # switch_git_branch_and_update 7 | # Switch the branches of .git repos into a specific branch and update from the latest remote origin 8 | # The command accepts two optional argument which is the new branch to checkout 9 | # If no argument was passed then the command will default and switch all repos to master 10 | # If a second argument is passed then it will from that remote, if not it will default to origin 11 | # Default paramteres: git checkout master; git pull origin master 12 | 13 | switch_git_branch_and_update() { 14 | 15 | if [[ $@ == *'-s'* ]]; then 16 | echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands" 17 | else 18 | # if a second parameter is defined as a remote it will be used, if not then it will pull from origin 19 | REMOTE=${1:-origin} 20 | BRANCH=${2:-master} 21 | 22 | printf "${RED}Please note that this will stash any changes made in the repos and flip the current branch${NC}\n" 23 | read -p "Are you sure you want to proceed? [Y/N] " -n 1; 24 | echo "" 25 | 26 | if [[ $REPLY =~ ^[Yy]$ ]]; then 27 | if ! [[ $BRANCH =~ ^(master|development)$ ]]; then 28 | printf "\nYou are switching to a non-default branch ... will fetch repositories first\n" 29 | # Since this function already accepts params passed 30 | # We need to check if any of the params passed is the -s which indicates this should run on a single folder 31 | execute -g "echo ''; git fetch; git branch | grep -w $BRANCH > /dev/null && git stash && git checkout $BRANCH && git pull $REMOTE $BRANCH || echo 'This branch does not exist in this repo'; echo''" 32 | else 33 | execute -g "echo ''; git branch | grep -w $BRANCH > /dev/null && git stash && git checkout $BRANCH && git pull $REMOTE $BRANCH || echo 'This branch does not exist in this repo'; echo''" 34 | fi 35 | fi; 36 | fi; 37 | } 38 | -------------------------------------------------------------------------------- /bash-it/beamery.plugin.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cite about-plugin 4 | about-plugin 'beamery helpers functions' 5 | 6 | #!/usr/bin/env bash 7 | 8 | beamery() { 9 | 10 | if [ -d "${HOME}/.bash_it/plugins/available/beamery/plugins" ]; then 11 | for config_file in ${HOME}/.bash_it/plugins/available/beamery/plugins/*.bash 12 | do 13 | if [ -e "${config_file}" ]; then 14 | source $config_file 15 | fi 16 | done 17 | fi 18 | 19 | # Check if the second param passed is a call to the help .. if so launch the help if not .. execute the command 20 | if [[ $1 == "update" ]]; then 21 | git -C "${HOME}/.beamery" pull origin master 22 | elif [[ $1 == "help" ]]; then 23 | if [[ -z $2 ]]; then 24 | printf "We cannot execute help without specifying the command you wish you show help for e.g., ${YELLOW}beamery audit_git_branches --help${NC} or ${YELLOW}beamery help audit_git_branches${NC} \nAlternatively, you can execute ${YELLOW}beamery --help${NC} or ${YELLOW}beamery -h${NC} for general help\n" 25 | else 26 | help $2 27 | fi; 28 | elif [[ $1 == "--help" || $1 == "-h" ]]; then 29 | help beamery 30 | elif [[ $2 = "--help" ]]; then 31 | help $1 32 | else 33 | # Execute the command/function passed as an argument 34 | $@ 35 | fi 36 | 37 | help() { 38 | if [[ $1 = "beamery" ]]; then 39 | printf "\n${YELLOW}Beamery Microservices Helpers${NC}\nBeamery Micro-services Helpers are shell helper functions that will automate and facilitate manipulating micro-services repos and in general any multiple folders in a certain directory\n" 40 | printf "\n${YELLOW}Supported Plugins:${NC}\n" 41 | for config_file in ${HOME}/.bash_it/plugins/available/beamery/plugins/*.bash 42 | do 43 | printf "\n${YELLOW} `echo $(basename $config_file) | sed "s/.*\///" | sed "s/\..*//"` ${NC}" 44 | printf "\n" && grep '#' "${config_file}" | cut -c 2- | tail -n +3 45 | done 46 | printf "\n${YELLOW}execute${NC}\nExecute a passed function on all the repos or a single repo if provided the -s flag\n" 47 | printf "\n${YELLOW}update${NC}\nUpdates the main repo to fetch any updates on the plugins or the source itself\n" 48 | elif [[ $1 = "execute" ]]; then 49 | echo "Executes a passed command in each repository" 50 | else 51 | printf "\n" && grep '#' "$HOME/.bash_it/plugins/available/beamery/plugins/${1}.bash" | cut -c 2- | tail -n +3 52 | fi 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /beamery/beamery.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | beamery() { 4 | 5 | if [ -d "${HOME}/.beamery/beamery/plugins/" ]; then 6 | for config_file in ${HOME}/.beamery/beamery/plugins/*.sh 7 | do 8 | if [ -e "${config_file}" ]; then 9 | source $config_file 10 | fi 11 | done 12 | fi 13 | 14 | # Check if the second param passed is a call to the help .. if so launch the help if not .. execute the command 15 | if [[ $1 == "update" ]]; then 16 | git -C "${HOME}/.beamery" pull origin master 17 | elif [[ $1 == "help" ]]; then 18 | if [[ -z $2 ]]; then 19 | printf "We cannot execute help without specifying the command you wish you show help for e.g., ${YELLOW}beamery audit_git_branches --help${NC} or ${YELLOW}beamery help audit_git_branches${NC} \nAlternatively, you can execute ${YELLOW}beamery --help${NC} or ${YELLOW}beamery -h${NC} for general help\n" 20 | else 21 | help $2 22 | fi; 23 | elif [[ $1 == "--help" || $1 == "-h" ]]; then 24 | help beamery 25 | elif [[ $2 = "--help" ]]; then 26 | help $1 27 | else 28 | # Execute the command/function passed as an argument 29 | $@ 30 | fi 31 | 32 | help() { 33 | if [[ $1 = "beamery" ]]; then 34 | printf "\n${YELLOW}Beamery Microservices Helpers${NC}\nBeamery Micro-services Helpers are shell helper functions that will automate and facilitate manipulating micro-services repos and in general any multiple folders in a certain directory\n" 35 | printf "\n${YELLOW}Supported Plugins:${NC}\n" 36 | for config_file in ${HOME}/.beamery/beamery/plugins/*.sh 37 | do 38 | printf "\n${YELLOW} `echo $(basename $config_file) | sed "s/.*\///" | sed "s/\..*//"` ${NC}" 39 | printf "\n" && grep '#' "${config_file}" | cut -c 2- | tail -n +3 40 | done 41 | printf "\n${YELLOW}execute${NC}\nExecute a passed function on all the repos or a single repo if provided the -s flag\n" 42 | printf "\n${YELLOW}update${NC}\nUpdates the main repo to fetch any updates on the plugins or the source itself\n" 43 | elif [[ $1 = "execute" ]]; then 44 | echo "Executes a passed command in each repository" 45 | else 46 | printf "\n" && grep '#' "${HOME}/.beamery/beamery/plugins/${1}.sh" | cut -c 2- | tail -n +3 47 | fi 48 | } 49 | } 50 | 51 | _beamery_comp() 52 | { 53 | local cur prev opts prevprev 54 | COMPREPLY=() 55 | cur="${COMP_WORDS[COMP_CWORD]}" 56 | prev="${COMP_WORDS[COMP_CWORD-1]}" 57 | chose_opt="${COMP_WORDS[1]}" 58 | file_type="${COMP_WORDS[2]}" 59 | opts="execute update" 60 | if [ -d "$HOME/.beamery/beamery/plugins/" ]; then 61 | for config_file in $HOME/.beamery/beamery/plugins/*.sh 62 | do 63 | if [ -e "${config_file}" ]; then 64 | opts+=" `basename $config_file .sh`" 65 | fi 66 | done 67 | fi 68 | case "${chose_opt}" in 69 | help) 70 | local help_args="$(echo "${opts}" | cut -d " " -f2-)" 71 | COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) ) 72 | return 0 73 | ;; 74 | esac 75 | COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) 76 | return 0 77 | } 78 | 79 | complete -F _beamery_comp beamery 80 | -------------------------------------------------------------------------------- /zsh/beamery/beamery.plugin.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | beamery() { 4 | 5 | if [ -d "${HOME}/.oh-my-zsh/plugins/beamery/plugins" ]; then 6 | for config_file in ${HOME}/.oh-my-zsh/plugins/beamery/plugins/*.zsh 7 | do 8 | if [ -e "${config_file}" ]; then 9 | source $config_file 10 | fi 11 | done 12 | fi 13 | 14 | # Check if the second param passed is a call to the help .. if so launch the help if not .. execute the command 15 | if [[ $1 == "update" ]]; then 16 | git -C "${HOME}/.beamery" pull origin master 17 | elif [[ $1 == "help" ]]; then 18 | if [[ -z $2 ]]; then 19 | printf "We cannot execute help without specifying the command you wish you show help for e.g., ${YELLOW}beamery audit_git_branches --help${NC} or ${YELLOW}beamery help audit_git_branches${NC} \nAlternatively, you can execute ${YELLOW}beamery --help${NC} or ${YELLOW}beamery -h${NC} for general help\n" 20 | else 21 | help $2 22 | fi; 23 | elif [[ $1 == "--help" || $1 == "-h" ]]; then 24 | help beamery 25 | elif [[ $2 = "--help" ]]; then 26 | help $1 27 | else 28 | # Execute the command/function passed as an argument 29 | $@ 30 | fi 31 | 32 | help() { 33 | if [[ $1 = "beamery" ]]; then 34 | printf "\n${YELLOW}Beamery Microservices Helpers${NC}\nBeamery Micro-services Helpers are shell helper functions that will automate and facilitate manipulating micro-services repos and in general any multiple folders in a certain directory\n" 35 | printf "\n${YELLOW}Supported Plugins:${NC}\n" 36 | for config_file in ${HOME}/.oh-my-zsh/plugins/beamery/plugins/*.zsh 37 | do 38 | printf "\n${YELLOW} `echo $(basename $config_file) | sed "s/.*\///" | sed "s/\..*//"` ${NC}" 39 | printf "\n" && grep '#' "${config_file}" | cut -c 2- | tail -n +3 40 | done 41 | printf "\n${YELLOW}execute${NC}\nExecute a passed function on all the repos or a single repo if provided the -s flag\n" 42 | printf "\n${YELLOW}update${NC}\nUpdates the main repo to fetch any updates on the plugins or the source itself\n" 43 | elif [[ $1 = "execute" ]]; then 44 | echo "Executes a passed command in each repository" 45 | else 46 | printf "\n" && grep '#' "$HOME/.oh-my-zsh/plugins/beamery/plugins/${1}.zsh" | cut -c 2- | tail -n +3 47 | fi 48 | } 49 | 50 | } 51 | 52 | _beamery_comp () 53 | { 54 | local -a arg _help 55 | local expl 56 | typeset -A opt_args 57 | 58 | _help=('--help[Display a description about the command]') 59 | 60 | arg=() 61 | 62 | if [ -d "${HOME}/.oh-my-zsh/plugins/beamery/plugins" ]; then 63 | for config_file in ${HOME}/.oh-my-zsh/plugins/beamery/plugins/*.zsh 64 | do 65 | if [ -e "${config_file}" ]; then 66 | EXCERPT=$(grep '#' "${config_file}" | cut -c 2- | tail -n +3 | head -n 1) 67 | arg+=("`basename $config_file .zsh`: $EXCERPT") 68 | fi 69 | done 70 | arg+=("execute: Execute a passed function on all the repos or a single repo if provided the -s flag") 71 | arg+=("update: Updates the main repo to fetch any updates on the plugins or the source itself") 72 | fi 73 | 74 | _arguments \ 75 | $_help \ 76 | '*:: :->subcmds' && return 0 77 | 78 | if (( CURRENT == 1 )); then 79 | _describe -t commands "beamery subcommand" arg 80 | return 81 | fi 82 | case "$words[1]" in 83 | *) 84 | _arguments \ 85 | $_help \ 86 | ;; 87 | esac 88 | } 89 | 90 | compdef _beamery_comp beamery 91 | -------------------------------------------------------------------------------- /zsh/beamery/pluginsInterface.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Colors and visual Configurations 4 | MAGENTA='\033[35m' 5 | RED='\033[31m' 6 | YELLOW='\033[33m' 7 | NC='\033[0m' 8 | 9 | # Some helper functions to check if a certain command exists 10 | command_exists () { 11 | type "$1" &> /dev/null ; 12 | } 13 | 14 | # Executes a passed command in each repository. This is the main core function as it will iterate on all the subfolders in a given 15 | # folder and execute the command passed as an argument in each sub-folder 16 | # The function accepts three flag options: 17 | # -h: execute in hidden folders as well 18 | # -n: executes only in folders where valid node.js code is found 19 | # -g: executes only in folders where a valid git repo is found 20 | 21 | execute() { 22 | 23 | # This is the main function that will execute the passed function based on the option parameters 24 | # The paramteres are: 25 | # IS_NODE_FOLDER: Which will execute the function if a package.json file was found -> valid node.js code 26 | # IS_GIT_FOLDER: Which will execute the function if a .git/config file was found -> valid git repo 27 | 28 | _execute() { 29 | if [[ $IS_NODE_FOLDER = 1 ]]; then 30 | if [ -f "package.json" ]; then 31 | [ $IS_SHOW_FOLDER_TYPE = 1 ] && printf "\nExecuting command as folder is identified to contain valid ${YELLOW}Node.js${NC} code\n" 32 | [ $IS_HIDE_FOLDER_NAME = 0 ] && printf "${YELLOW}[Repository]${NC} ${MAGENTA}$1${NC}\n"; 33 | eval "${@%$1}" 34 | fi 35 | elif [[ $IS_GIT_FOLDER = 1 ]]; then 36 | if [ -f ".git/config" ]; then 37 | [ $IS_SHOW_FOLDER_TYPE = 1 ] && printf "\nExecuting command as folder is identified to be a valid ${YELLOW}git${NC} repository\n" 38 | [ $IS_HIDE_FOLDER_NAME = 0 ] && printf "${YELLOW}[Repository]${NC} ${MAGENTA}$1${NC}\n"; 39 | eval "${@%$1}" 40 | fi 41 | else 42 | printf "${YELLOW}[Repository]${NC} ${MAGENTA}$1${NC}\n"; eval "${@%$1}"; echo "" 43 | fi 44 | } 45 | 46 | # Reset in case getopts has been used previously in the shell 47 | # The advantages of getopts are: 48 | # It's portable, and will work in e.g. dash. 49 | # It can handle things like -vf filename in the expected Unix way, automatically. 50 | # For more information on getopts: http://wiki.bash-hackers.org/howto/getopts_tutorial 51 | 52 | OPTIND=1 53 | 54 | # Initialize our own variables: 55 | 56 | IS_NODE_FOLDER=0 57 | IS_GIT_FOLDER=0 58 | IS_HIDDEN_FOLDER=0 59 | IS_SINGLE_FOLDER=0 60 | IS_SHOW_FOLDER_TYPE=0 61 | IS_HIDE_FOLDER_NAME=0 62 | 63 | while getopts "shngpf" opt; do 64 | case "$opt" in 65 | s) IS_SINGLE_FOLDER=1 66 | ;; 67 | p) IS_SHOW_FOLDER_TYPE=1 68 | ;; 69 | h) IS_HIDDEN_FOLDER=1 70 | ;; 71 | n) IS_NODE_FOLDER=1 72 | ;; 73 | g) IS_GIT_FOLDER=1 74 | ;; 75 | f) IS_HIDE_FOLDER_NAME=1 76 | ;; 77 | esac 78 | done 79 | 80 | shift $((OPTIND-1)) 81 | [ "$1" = "--" ] && shift 82 | 83 | # Save and keep track of the parent directory to revert back to after operations are done 84 | PARENT_FOLDER=`pwd` 85 | 86 | # Check if the user wishes to execute the function only at the current folder 87 | if [[ $IS_SINGLE_FOLDER = 1 ]]; then 88 | _execute $@; 89 | else 90 | # Check if the hidden flag is turned on with the -h param 91 | if [[ $IS_HIDDEN_FOLDER = 1 ]]; then 92 | find . -maxdepth 1 -type d \( ! -name . \) | while read -r SUBFOLDER; do cd "$PARENT_FOLDER/$SUBFOLDER" && _execute $SUBFOLDER $@; done; 93 | echo; 94 | else 95 | find . -maxdepth 1 -type d \( ! -name ".*" \) | while read -r SUBFOLDER; do cd "$PARENT_FOLDER/$SUBFOLDER" && _execute $SUBFOLDER $@; done; 96 | echo; 97 | fi 98 | fi 99 | 100 | # Go back to parent directory after finishing 101 | cd $PARENT_FOLDER 102 | } 103 | -------------------------------------------------------------------------------- /bash-it/beamery/pluginsInterface.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Colors and visual Configurations 4 | MAGENTA='\033[35m' 5 | RED='\033[31m' 6 | YELLOW='\033[33m' 7 | NC='\033[0m' 8 | 9 | # Some helper functions to check if a certain command exists 10 | command_exists () { 11 | type "$1" &> /dev/null ; 12 | } 13 | 14 | # Executes a passed command in each repository. This is the main core function as it will iterate on all the subfolders in a given 15 | # folder and execute the command passed as an argument in each sub-folder 16 | # The function accepts three flag options: 17 | # -h: execute in hidden folders as well 18 | # -n: executes only in folders where valid node.js code is found 19 | # -g: executes only in folders where a valid git repo is found 20 | 21 | execute() { 22 | 23 | # This is the main function that will execute the passed function based on the option parameters 24 | # The paramteres are: 25 | # IS_NODE_FOLDER: Which will execute the function if a package.json file was found -> valid node.js code 26 | # IS_GIT_FOLDER: Which will execute the function if a .git/config file was found -> valid git repo 27 | 28 | _execute() { 29 | if [[ $IS_NODE_FOLDER = 1 ]]; then 30 | if [ -f "package.json" ]; then 31 | [ $IS_SHOW_FOLDER_TYPE = 1 ] && printf "\nExecuting command as folder is identified to contain valid ${YELLOW}Node.js${NC} code\n" 32 | [ $IS_HIDE_FOLDER_NAME = 0 ] && printf "${YELLOW}[Repository]${NC} ${MAGENTA}$1${NC}\n"; 33 | eval "${@%$1}" 34 | fi 35 | elif [[ $IS_GIT_FOLDER = 1 ]]; then 36 | if [ -f ".git/config" ]; then 37 | [ $IS_SHOW_FOLDER_TYPE = 1 ] && printf "\nExecuting command as folder is identified to be a valid ${YELLOW}git${NC} repository\n" 38 | [ $IS_HIDE_FOLDER_NAME = 0 ] && printf "${YELLOW}[Repository]${NC} ${MAGENTA}$1${NC}\n"; 39 | eval "${@%$1}" 40 | fi 41 | else 42 | printf "${YELLOW}[Repository]${NC} ${MAGENTA}$1${NC}\n"; eval "${@%$1}"; echo "" 43 | fi 44 | } 45 | 46 | # Reset in case getopts has been used previously in the shell 47 | # The advantages of getopts are: 48 | # It's portable, and will work in e.g. dash. 49 | # It can handle things like -vf filename in the expected Unix way, automatically. 50 | # For more information on getopts: http://wiki.bash-hackers.org/howto/getopts_tutorial 51 | 52 | OPTIND=1 53 | 54 | # Initialize our own variables: 55 | 56 | IS_NODE_FOLDER=0 57 | IS_GIT_FOLDER=0 58 | IS_HIDDEN_FOLDER=0 59 | IS_SINGLE_FOLDER=0 60 | IS_SHOW_FOLDER_TYPE=0 61 | IS_HIDE_FOLDER_NAME=0 62 | 63 | while getopts "shngpf" opt; do 64 | case "$opt" in 65 | s) IS_SINGLE_FOLDER=1 66 | ;; 67 | p) IS_SHOW_FOLDER_TYPE=1 68 | ;; 69 | h) IS_HIDDEN_FOLDER=1 70 | ;; 71 | n) IS_NODE_FOLDER=1 72 | ;; 73 | g) IS_GIT_FOLDER=1 74 | ;; 75 | f) IS_HIDE_FOLDER_NAME=1 76 | ;; 77 | esac 78 | done 79 | 80 | shift $((OPTIND-1)) 81 | [ "$1" = "--" ] && shift 82 | 83 | # Save and keep track of the parent directory to revert back to after operations are done 84 | PARENT_FOLDER=`pwd` 85 | 86 | # Check if the user wishes to execute the function only at the current folder 87 | if [[ $IS_SINGLE_FOLDER = 1 ]]; then 88 | _execute $@; 89 | else 90 | # Check if the hidden flag is turned on with the -h param 91 | if [[ $IS_HIDDEN_FOLDER = 1 ]]; then 92 | find . -maxdepth 1 -type d \( ! -name . \) | while read -r SUBFOLDER; do cd "$PARENT_FOLDER/$SUBFOLDER" && _execute $SUBFOLDER $@; done; 93 | echo; 94 | else 95 | find . -maxdepth 1 -type d \( ! -name ".*" \) | while read -r SUBFOLDER; do cd "$PARENT_FOLDER/$SUBFOLDER" && _execute $SUBFOLDER $@; done; 96 | echo; 97 | fi 98 | fi 99 | 100 | # Go back to parent directory after finishing 101 | cd $PARENT_FOLDER 102 | } 103 | -------------------------------------------------------------------------------- /beamery/pluginsInterface.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Colors and visual Configurations 4 | MAGENTA='\033[35m' 5 | RED='\033[31m' 6 | YELLOW='\033[33m' 7 | NC='\033[0m' 8 | 9 | # Some helper functions to check if a certain command exists 10 | command_exists () { 11 | type "$1" &> /dev/null ; 12 | } 13 | 14 | # Executes a passed command in each repository. This is the main core function as it will iterate on all the subfolders in a given 15 | # folder and execute the command passed as an argument in each sub-folder 16 | # The function accepts three flag options: 17 | # -h: execute in hidden folders as well 18 | # -n: executes only in folders where valid node.js code is found 19 | # -g: executes only in folders where a valid git repo is found 20 | 21 | execute() { 22 | 23 | # This is the main function that will execute the passed function based on the option parameters 24 | # The paramteres are: 25 | # IS_NODE_FOLDER: Which will execute the function if a package.json file was found -> valid node.js code 26 | # IS_GIT_FOLDER: Which will execute the function if a .git/config file was found -> valid git repo 27 | 28 | _execute() { 29 | if [[ $IS_NODE_FOLDER = 1 ]]; then 30 | if [ -f "package.json" ]; then 31 | [ $IS_SHOW_FOLDER_TYPE = 1 ] && printf "\nExecuting command as folder is identified to contain valid ${YELLOW}Node.js${NC} code\n" 32 | [ $IS_HIDE_FOLDER_NAME = 0 ] && printf "${YELLOW}[Repository]${NC} ${MAGENTA}$1${NC}\n"; 33 | eval "${@%$1}" 34 | fi 35 | elif [[ $IS_GIT_FOLDER = 1 ]]; then 36 | if [ -f ".git/config" ]; then 37 | [ $IS_SHOW_FOLDER_TYPE = 1 ] && printf "\nExecuting command as folder is identified to be a valid ${YELLOW}git${NC} repository\n" 38 | [ $IS_HIDE_FOLDER_NAME = 0 ] && printf "${YELLOW}[Repository]${NC} ${MAGENTA}$1${NC}\n"; 39 | eval "${@%$1}" 40 | fi 41 | else 42 | printf "${YELLOW}[Repository]${NC} ${MAGENTA}$1${NC}\n"; eval "${@%$1}"; echo "" 43 | fi 44 | } 45 | 46 | # Reset in case getopts has been used previously in the shell 47 | # The advantages of getopts are: 48 | # It's portable, and will work in e.g. dash. 49 | # It can handle things like -vf filename in the expected Unix way, automatically. 50 | # For more information on getopts: http://wiki.bash-hackers.org/howto/getopts_tutorial 51 | 52 | OPTIND=1 53 | 54 | # Initialize our own variables: 55 | 56 | IS_NODE_FOLDER=0 57 | IS_GIT_FOLDER=0 58 | IS_HIDDEN_FOLDER=0 59 | IS_SINGLE_FOLDER=0 60 | IS_SHOW_FOLDER_TYPE=0 61 | IS_HIDE_FOLDER_NAME=0 62 | 63 | while getopts "shngpf" opt; do 64 | case "$opt" in 65 | s) IS_SINGLE_FOLDER=1 66 | ;; 67 | p) IS_SHOW_FOLDER_TYPE=1 68 | ;; 69 | h) IS_HIDDEN_FOLDER=1 70 | ;; 71 | n) IS_NODE_FOLDER=1 72 | ;; 73 | g) IS_GIT_FOLDER=1 74 | ;; 75 | f) IS_HIDE_FOLDER_NAME=1 76 | ;; 77 | esac 78 | done 79 | 80 | shift $((OPTIND-1)) 81 | [ "$1" = "--" ] && shift 82 | 83 | # Save and keep track of the parent directory to revert back to after operations are done 84 | export PARENT_FOLDER=`pwd` 85 | 86 | # Check if the user wishes to execute the function only at the current folder 87 | if [[ $IS_SINGLE_FOLDER = 1 ]]; then 88 | _execute $@; 89 | else 90 | # Check if the hidden flag is turned on with the -h param 91 | if [[ $IS_HIDDEN_FOLDER = 1 ]]; then 92 | find . -maxdepth 1 -type d \( ! -name . \) | while read -r SUBFOLDER; do cd "$PARENT_FOLDER/$SUBFOLDER" && _execute $SUBFOLDER $@; done; 93 | echo; 94 | else 95 | find . -maxdepth 1 -type d \( ! -name ".*" \) | while read -r SUBFOLDER; do cd "$PARENT_FOLDER/$SUBFOLDER" && _execute $SUBFOLDER $@; done; 96 | echo; 97 | fi 98 | fi 99 | 100 | # Go back to parent directory after finishing 101 | cd $PARENT_FOLDER 102 | } 103 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Colors and visual Configurations 4 | MAGENTA='\033[35m' 5 | RED='\033[31m' 6 | YELLOW='\033[33m' 7 | NC='\033[0m' 8 | 9 | export SOURCE_LOCATION=`pwd` 10 | 11 | if [ ! -n "$BEAMERY" ]; then 12 | BEAMERY=~/.beamery 13 | fi 14 | 15 | # Check if Beamery micromanage is alreayd installed and ask for am update or re-install 16 | if [ -d "$BEAMERY" ]; then 17 | 18 | printf "${YELLOW}You already have Beamery Micromanage installed.${NC}\n" 19 | printf "Please select if you wish to ${RED}re-install${NC} or ${MAGENTA}update${NC} Beamery Micromanage [R/U]:" && read -n1 OPTION 20 | echo "" 21 | 22 | if [[ $OPTION =~ ^[uU]$ ]]; then 23 | cd "$BEAMERY" && git pull origin master && exit 0 24 | elif [[ $OPTION =~ ^[rR]$ ]]; then 25 | rm -rf "$BEAMERY" 26 | else exit 0 27 | fi 28 | fi 29 | 30 | # Set the environment variables 31 | set_environment_exports() { 32 | 33 | # Setting $BASH to maintain backwards compatibility 34 | # Getting the user's OS type in order to load the correct installation and configuration scripts 35 | if [[ "$OSTYPE" == "linux-gnu" ]]; then 36 | if ! grep -q "${1}" "${HOME}/.bashrc" ; then 37 | echo "Editing ${YELLOW}.bashrc${NC} to load beamery-micromanage on Terminal launch" 38 | printf "\n%s\n" "${1}" >> "${HOME}/.bashrc" 39 | fi 40 | elif [[ "$OSTYPE" == "darwin"* ]]; then 41 | if ! grep -q "${1}" "${HOME}/.bash_profile" ; then 42 | echo "Editing ${YELLOW}.bash_profile${NC} to load beamery-micromanage on Terminal launch" 43 | printf "\n%s\n" "${1}" >> "${HOME}/.bash_profile" 44 | fi 45 | fi 46 | 47 | # Check if we have a .zshrc regardless of the os .. and copy that to the zsh source file 48 | if [[ -f "$HOME/.zshrc" ]]; then 49 | if ! grep -q "${1}" "${HOME}/.zshrc" ; then 50 | printf "Noticed that you have ${RED}Zsh${NC} installed. \n(${RED}note: there might be some compatibility issues exporting the beamery tools there as well)${NC}\n" 51 | read -p "Are you sure you want to proceed exporting beamery tools in your .zshrc ? [Y/N] " -n 1; 52 | if [[ $REPLY =~ ^[Yy]$ ]]; then 53 | echo "Editing ${YELLOW}.zshrc${NC} to load beamery-micromanage on Terminal launch" 54 | printf "\n%s\n" "${1}" >> "${HOME}/.zshrc" 55 | fi 56 | fi 57 | fi 58 | } 59 | 60 | # Preliminary Checks 61 | hash git >/dev/null 2>&1 || { 62 | echo "${RED}Error:${NC} git is not installed. We cannot proceed with the installation as we require to pull down files from Github" 63 | exit 1 64 | } 65 | 66 | git clone --depth=1 https://github.com/SeedJobs/beamery-micromanage.git $BEAMERY || { 67 | printf "${RED}Error:${NC} git clone of beamery-micromanage repo failed\n" 68 | exit 1 69 | } 70 | 71 | # Prompt user to select his type of shell 72 | printf " 73 | Please select what shell helper you need to install the plugins for ${MAGENTA}(bash-it | oh-my-zsh | none (for standalone installation)${NC} ):" && read SHELL_TYPE 74 | 75 | install_manually() { 76 | 77 | 78 | # We need to makre sure that we have a .beamery folder in home 79 | [ -d ${HOME}/.beamery ] || mkdir "$HOME/.beamery" 80 | 81 | set_environment_exports "source $HOME/.beamery/beamery/beamery.sh" 82 | 83 | printf "Do not forget now to enable the plugin by sourcing your .bash_profile, .bashrc or .zshrc\n" 84 | } 85 | 86 | if [[ "$SHELL_TYPE" == "bash-it" ]]; then 87 | 88 | if [[ -d ${HOME}/.bash_it ]]; then 89 | ln -sf "$HOME/.beamery/bash-it/beamery.completion.bash" "${HOME}/.bash_it/completion/available" 90 | ln -sf "$HOME/.beamery/bash-it/beamery.plugin.bash" "${HOME}/.bash_it/plugins/available" 91 | ln -sf "$HOME/.beamery/bash-it/beamery" "${HOME}/.bash_it/plugins/available" 92 | else 93 | printf "We noticed that bash-it is not installed .. installing the plugins manually" && install_manually 94 | fi 95 | 96 | printf " 97 | Do not forget now to enable completion and plugins by reloading shell first by resourcing your bash_profile or bashrc and then executing: 98 | 99 | bash-it enable completion beamery 100 | bash-it enable plugin beamery 101 | 102 | " 103 | 104 | elif [[ "$SHELL_TYPE" == "oh-my-zsh" ]]; then 105 | if [[ -d ${HOME}/.oh-my-zsh ]]; then 106 | ln -sf "$HOME/.beamery/zsh/beamery" "${HOME}/.oh-my-zsh/plugins/" 107 | else 108 | printf "We noticed that oh-my-zh is not installed .. installing the plugins manually" && install_manually 109 | fi 110 | printf " 111 | Do not forget now to enable the plugin by adding beamery to your .zshrc plugins array and then resourcing your bash_profile or bashrc 112 | " 113 | else 114 | install_manually 115 | fi 116 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Beamery Micromanage - A Micro-services Helpers Framework 2 | 3 | At [Beamery](http://beamery.com) we follow [Microservices Architecture](https://en.wikipedia.org/wiki/Microservices) which has various advantages from it being easier to scale, deploy independent services to elimination of any long-term commitment to a technology stack. However, Microservices Architecture also has its fair number of disadvantages as testing and inter-services communication become harder. 4 | 5 | We currently have a good 50+ git repository. Developing features affect very often more than one of these repos. Changing branches, syncing and development is hard as you have to keep flipping between multiple terminal tabs to make sure all the repos are in order. Beamery Micro-services Helpers are shell helper functions that will automate and facilitate manipulating micro-services repos and in general any multiple folders in a certain directory. 6 | 7 | ![demo](http://g.recordit.co/zyhTtLDI56.gif) 8 | 9 | > supports bash (version >= 4.0) and zsh (>= 5.0) 10 | 11 | These helper functions are configured out of the box to work [bash-it](https://github.com/Bash-it/bash-it) plugins framework for bash and [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) plugins framework for zsh. 12 | 13 | ## Installation 14 | 15 | You can install the helpers using the installation script by executing `. install.sh` .. the script will then prompt to select the type of shell you are using, check for the existence of any shell helper and then install the relevant helpers accordingly. 16 | 17 | ### One-liner installation 18 | 19 | You can install this pugin via the command-line with either curl or wget: 20 | 21 | #### via `curl` 22 | 23 | ```bash 24 | bash -c "$(curl -fsSL https://raw.githubusercontent.com/SeedJobs/beamery-micromanage/master/install.sh)" 25 | ``` 26 | 27 | #### via `wget` 28 | 29 | ```bash 30 | bash -c "$(wget https://raw.githubusercontent.com/SeedJobs/beamery-micromanage/master/install.sh -O -)" 31 | ``` 32 | 33 | The manual installation details for these are: 34 | 35 | #### bash-it 36 | 37 | bash-it separates plugins, aliases and completion functions into three separate folders. To install the completion you will need to copy `bash-it/beamery.completion.bash` to `$BASH_IT/completion/available` which is usually is in `$HOME/.bash_it/completion/available`. 38 | 39 | To Install the plugin, you need to copy both the main plugin in `bash-it/beamery.plugin.bash` and the plugins folder in `bash-it/beamery/` to `$BASH_IT/plugins/available` which is usually is in `$HOME/.bash_it/plugins/available` 40 | 41 | Activating now the plugins and completion is done via executing both `bash-it enable completion beamery` and `bash-it enable plugin beamery` in the terminal and then reloading the sherll either by `reload` which is a bash-it alias or by sourcing `.bash_profile` or `.bashrc` depending on your OSX by executing `source $HOME/.bash_profile; source $HOME/.bashrc` 42 | 43 | #### oh-my-zsh 44 | 45 | oh-my-zsh have all their plugin in the plugins folder inside the installation directory of `oh-my-zsh` which is usually in `$HOMR/.oh-my-zsh/plugins`. 46 | 47 | Installing oh-my-zsh beamery plugin is done by copying beamery folder in `zsh/beamery/` to oh-my-zsh plugins directory and then activating the plugin by editing your `$HOME/.zshrc` and adding `beamery` to the list of plugins so that you have something similar to: 48 | 49 | ```bash 50 | # Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) 51 | # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ 52 | # Example format: plugins=(rails git textmate ruby lighthouse) 53 | # Add wisely, as too many plugins slow down shell startup. 54 | 55 | plugins=(brew git npm nvm node osx pyenv python scala sublime tmux beamery) 56 | ``` 57 | 58 | #### Manual 59 | 60 | If you do not use any shell halpers but still want to take advantage of these helper functions, you can still install them manually. Basically all what you need to do is source the main entry file which is in `manual/beamery.sh` from your `.bash_profile` or `.bashrc` depending on your OSX. Basically, i create a new folder in my `$HOME` and i call it `.beamery` so thats its hidden, and i copy the contents of `manual` inside so that i have: 61 | 62 | ``` 63 | ├── .beamery 64 | ├── beamery.sh 65 | ├── plugins 66 | └── pluginsInterface.sh 67 | ``` 68 | then i add the line `source $HOME/.beamery/beamery.sh` inside my `$HOME/.bash_profile` as i am on OSX but can be inside your `.bashrc` as well. Simply, reload by re-sourcing these files and you are good to go. 69 | 70 | ## What does it do ? 71 | 72 | Currently the helper functions configured are: 73 | 74 | - **audit_git_branches**: List all the branches of a .git repository sorted by date creation 75 | - **check_node_package_usage**: Check the places a certain npm package is used across all the repos 76 | - **clean_git_branches**: Total cleaning on branches by first performing deletion of remote branches that have been merged into master 77 | - **clean_git_local_branches**: Clean any local branches that have been deleted on remote 78 | - **clean_git_remote_branches**: Clean remote branches that have been merged into master and delete them from remotes as well 79 | - **clean_git_stash**: Clean any stashed commits 80 | - **clean_npm_modules**: Clean unused NPM modules from each repo 81 | - **generate_npm_report**: Generate NPM report using the npm-check module to inspect the state of our npm modules 82 | - **link_node_modules**: Remove all node_modules from all the repos and run zelda to link and download all 83 | - **list_git_active_branch**: List the current branches on the repos 84 | - **switch_git_branch**: Switch the branches of .git repos into a specific branch 85 | - **switch_git_branch_and_update**: Switch the branches of .git repos into a specific branch and update from the latest remote origin 86 | - **track_all_remote_git_branches**: Track all remote branches that are not being tracked locally 87 | - **update_git_branch**: Update .git branches from the latest remote origin 88 | 89 | > For the all the plugins, any supported flag (-g, -n, -h, -s) that are described below will be ported as well and executed with each function. So for example, if you wish to only execute `clean_npm_modules` inside of any folder you can then execute `beamery clean_npm_modules -s` 90 | 91 | For git functions, there are default params set for `pull` and `push` which are `origin` for your remote and `master` for local branch. However, these can be easily overridden by passing the desired names to the appropriate function call. Example: 92 | 93 | ```bash 94 | beamery switch_git_branch_and_update 95 | # This will call the sub functions for example like `git checkout master` and `git pull origin master` 96 | beamery switch_git_branch_and_update development 97 | # This will call the sub functions for example like `git checkout development` and `git pull origin development` 98 | beamery switch_git_branch_and_update development upstream 99 | # This will call the sub functions for example like `git checkout development` and `git pull upstream development` 100 | ``` 101 | 102 | ### Autocomplete 103 | 104 | Autocompletion is enabled by default and supports both zsh and bash. For zsh, hitting tab immediately after `beamery` will show the list of supported plugins to execute. Hitting a tab afterwards will add the `--help` flag which will show the help docs for that plugin. 105 | 106 | There is a dedicated `help` function that will be triggered by `beamery help PLUGIN_NAME` that will show the help docs for each plugin. 107 | 108 | > help can be also triggered by appending the `--help` flag after each call 109 | 110 | ### Shell Helpers Architecture 111 | 112 | The most common prerequisite before executing any "helper" function is to be able to execute that function on every repository you have. Adding new plugins is very easy, you just need to create a new file with the desired function name inside the `plugins` folder. Then, you need to make sure that the file will have: 113 | 114 | - `source "${HOME}/PATH_TO_INTERFACE/pluginsInterface.sh"` this is done to load the main plugins "interface" 115 | - Properly have comments in the file as these will be extracted to show the help docs 116 | - Executing the code in every folder is done by calling the main `execute` function and passing the set of commands you need to execute to that function. 117 | 118 | #### What is `execute` ? 119 | 120 | Execute takes a folder type as an argument. This tells the function to verify the folder contents before executing the function. For example, you only want to execute a `git fetch` if the folder processed is a valid git repo. The supported flags passed are: 121 | 122 | - **-s**: only execute the function selected in the current folder 123 | - **-g**: git folders examined by the existence of a valid `.git` folder inside 124 | - **-n**: node folders examined by the existence of a valid `package.json` folder inside 125 | - **-h**: include as well hidden folders as they are not parsed by default 126 | - **-p**: suppress the debug sentence when executing inside folders 127 | 128 | ```bash 129 | 130 | # Check if the hidden flag is turned on with the -h param 131 | if [[ $IS_HIDDEN_FOLDER = 1 ]]; then 132 | find . -maxdepth 1 -type d \( ! -name . \) | while read -r SUBFOLDER; do cd "$PARENT_FOLDER/$SUBFOLDER" && printf "\nRepository: ${MAGENTA}$SUBFOLDER${NC}\n" && _execute $@; done; 133 | else 134 | find . -maxdepth 1 -type d \( ! -name ".*" \) | while read -r SUBFOLDER; do cd "$PARENT_FOLDER/$SUBFOLDER" && printf "\nRepository: ${MAGENTA}$SUBFOLDER${NC}\n" && _execute $@; done; 135 | fi 136 | 137 | function _execute() { 138 | if [[ $IS_NODE_FOLDER = 1 ]]; then 139 | if [ -f "package.json" ]; then 140 | printf "\nExecuting command as folder is identified to contain valid ${YELLOW}Node.js${NC} code\n" 141 | eval $@ 142 | fi 143 | elif [[ $IS_GIT_FOLDER = 1 ]]; then 144 | if [ -f ".git/config" ]; then 145 | printf "\nExecuting command as folder is identified to be a valid ${YELLOW}git${NC} repository\n" 146 | eval $@ 147 | fi 148 | else 149 | eval "$@" 150 | fi 151 | } 152 | ``` 153 | 154 | ### Extending with your own plugins 155 | 156 | Adding new plugins is fairly straightforward. You just need to create a new plugin in the `plugins/` folder. The guidelines for creating plugins are: 157 | 158 | - The plugin filename will be the same as the command you wish to be executed 159 | - Each plugin should source the `pluginInterface` e.g., `source "${HOME}/.beamery/beamery/pluginsInterface.sh"`. You can refer to existing plugins to know the path for the interface depending on your shell implementation 160 | - Documentation and help for each plugin will be extracted directly from the comments in the plugin file. **Note**: The first line of the comment should be the plugin name 161 | - To handle the `-s` flag, you might need to implement special logic if you want to block the execution of that function. For example, check the `update_git_branch` plugin 162 | 163 | #### Updates 164 | 165 | Since the plugin links itself to bash-it, oh-my-zsh and sits as a git repo, updating it to pull any new plugins or changes is as easy as executing `beamery update` or simply going to your installation folder and pulling the latest from remote. 166 | --------------------------------------------------------------------------------