Skip to content

Commit

Permalink
various modifications on plugins and the interfaces to produce better…
Browse files Browse the repository at this point in the history
… output
  • Loading branch information
ahmadassaf committed Jun 22, 2017
1 parent 9218b3a commit a4f1db7
Show file tree
Hide file tree
Showing 43 changed files with 139 additions and 118 deletions.
4 changes: 2 additions & 2 deletions bash-it/beamery/plugins/audit_git_branches.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash"
# This is useful to identify dead branches

audit_git_branches() {
execute -g $@ "echo ""; git branch -vv";
execute -g $@ "echo ""; git branch -vv; echo ''";

printf "${YELLOW}\nHistorical Branches Data:\n${NC}";
execute -g $@ "echo""; git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/remotes"
execute -g $@ "echo ""; git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/remotes; echo "";"
}
13 changes: 13 additions & 0 deletions bash-it/beamery/plugins/check_node_package_usage.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Load the main plugins "interface"
source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash"

# check_node_package_usage
# Check the places a certain npm package is used across all the repos

check_node_package_usage() {

execute -n "grep -sw $1 ./package.json >/dev/null && printf '\e[1A\e[40C' && grep -sw '\"$1\":' ./package.json || printf '\e[1A\e[K'"

}
14 changes: 0 additions & 14 deletions bash-it/beamery/plugins/check_npm_usage.bash

This file was deleted.

5 changes: 1 addition & 4 deletions bash-it/beamery/plugins/clean_git_local_branches.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash"

clean_git_local_branches() {


# Check if gawk is installed which is not by default in mac systems
if ! type gawk &> /dev/null ; then
if [[ "$OSTYPE" == "darwin"* ]]; then
Expand All @@ -17,9 +16,7 @@ clean_git_local_branches() {
fi
fi

execute -g $@ "echo""; git fetch --all";
execute -g $@ "echo""; git remote prune origin"
execute -g $@ "echo""; git gc --prune=now"
execute -g $@ "echo""; git fetch --all && git remote prune origin && git gc --prune=now; echo''";

if [[ `git branch -vv | grep ': gone]'` ]]; then
printf "\n${YELLOW}Making sure that all 'gone' branches are also removed ..\n\n${NC}"
Expand Down
2 changes: 1 addition & 1 deletion bash-it/beamery/plugins/clean_git_remote_branches.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash"
# Clean remote branches that have been merged into master and delete them from remotes as well

clean_git_remote_branches() {
execute -g $@ "echo""; git branch -r --merged | egrep -v '(^\*|master|development)' | sed 's/origin\///g'| xargs -n 1 git push --delete origin"
execute -g $@ "echo""; git branch -r --merged | egrep -v '(^\*|master|development)' | sed 's/origin\///g'| xargs -n 1 git push --delete origin; echo ''"
}
2 changes: 1 addition & 1 deletion bash-it/beamery/plugins/clean_git_stash.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ clean_git_stash() {
read -p "Are you sure you want to proceed ? [Y/N] " -n 1;

if [[ $REPLY =~ ^[Yy]$ ]]; then
execute -g $@ "git stash clear && echo '--> done'"
execute -g $@ "echo ''; git stash clear && echo '--> done'"
fi
echo "";
}
16 changes: 14 additions & 2 deletions bash-it/beamery/plugins/generate_npm_report.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@ source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash"

generate_npm_report() {

check_npm_report() {
if [[ -f "npm-report.txt" ]]; then
read -p "We have detected that an npm-report already exists. Would you like to clear that out before ? [Y/N] " -n 1;
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf "npm-report.txt"
echo ""
fi;
fi;
}

if [[ $@ == *'-s'* ]]; then
echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands"
else
if command_exists npm-check ; then
execute -n "npm-check >> ../npm-report.txt"
check_npm_report
execute -n 'echo "Checking NPM modules in package.json"; echo [REPOSITORY] `basename $PWD` >> ../npm-report.txt; npm-check >> ../npm-report.txt'
else
printf 'npm-check module was not found. Installing now:';
npm install -g npm-check
execute -n "npm-check >> ../npm-report.txt"
check_npm_report
execute -n 'echo "Checking NPM modules in package.json"; echo [REPOSITORY] `basename $PWD` >> ../npm-report.txt; npm-check >> ../npm-report.txt'
fi
fi;
}
2 changes: 1 addition & 1 deletion bash-it/beamery/plugins/list_git_active_branch.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash"
# This is useful to know which branches are flipped on which repos

list_git_active_branch() {
execute -g $@ printf "'${YELLOW}' && git branch | grep '^\*' | cut -d' ' -f2 && printf '${NC}'"
execute -g $@ printf "'\e[1A\e[70CBranch: ${YELLOW}' && git branch | grep '^\*' | cut -d' ' -f2 && printf '${NC}'"
}
5 changes: 2 additions & 3 deletions bash-it/beamery/plugins/switch_git_branch.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ switch_git_branch() {
if [[ $REPLY =~ ^[Yy]$ ]]; then
if ! [[ $BRANCH =~ ^(master|development)$ ]]; then
printf "\nYou are switching to a non-default branch ... fetching first\n"
execute -g "git fetch; git stash; git checkout $BRANCH"
execute -g "echo''; git fetch; git stash; git checkout $BRANCH; echo''"
else
execute -g "git stash; git checkout $BRANCH"
execute -g "echo''; git stash; git checkout $BRANCH; echo''"
fi
fi;
echo "";
fi;
}
6 changes: 2 additions & 4 deletions bash-it/beamery/plugins/switch_git_branch_and_update.bash
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ switch_git_branch_and_update() {
printf "\nYou are switching to a non-default branch ... will fetch repositories first\n"
# Since this function already accepts params passed
# We need to check if any of the params passed is the -s which indicates this should run on a single folder
execute -g "git fetch; git stash; git checkout $BRANCH; git pull $REMOTE $BRANCH"
execute -g "echo ''; git fetch; git stash; git checkout $BRANCH; git pull $REMOTE $BRANCH; echo ''"
else
execute -g "git stash; git checkout $BRANCH; git pull $REMOTE $BRANCH"
execute -g "echo ''; git stash; git checkout $BRANCH; git pull $REMOTE $BRANCH; echo''"
fi
fi;
echo "";
fi;

}
2 changes: 1 addition & 1 deletion bash-it/beamery/plugins/track_all_remote_git_branches.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ source "${HOME}/.bash_it/plugins/available/beamery/pluginsInterface.bash"
# This is useful when we want to clean out local branches and need to fetch all remote branches

track_all_remote_git_branches() {
execute -g $@ git branch -r | grep -v '\->' | while read remote; do git branch --track ${remote#origin/} $remote > /dev/null; done
execute -g $@ "git branch -r | grep -v '\->' | while read remote; do git branch --track ${remote#origin/} $remote > /dev/null; done;"
echo "--> All remote branches tracked"
}
2 changes: 1 addition & 1 deletion bash-it/beamery/plugins/update_git_branch.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ update_git_branch() {
if [[ $@ == *'-s'* ]]; then
echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands"
else
execute -g "git pull ${2:-origin} ${1:-master}"
execute -g "echo''; git pull ${2:-origin} ${1:-master}; echo''"
fi;
}
6 changes: 3 additions & 3 deletions bash-it/beamery/pluginsInterface.bash
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ execute() {
if [[ $IS_NODE_FOLDER = 1 ]]; then
if [ -f "package.json" ]; then
[ $IS_SHOW_FOLDER_TYPE = 1 ] && printf "\nExecuting command as folder is identified to contain valid ${YELLOW}Node.js${NC} code\n"
printf "Repository: ${MAGENTA}$1${NC} " && eval "${@%$1}"
printf "${YELLOW}[Repository]${NC} ${MAGENTA}$1${NC} " && eval "${@%$1}"
fi
elif [[ $IS_GIT_FOLDER = 1 ]]; then
if [ -f ".git/config" ]; then
[ $IS_SHOW_FOLDER_TYPE = 1 ] && printf "\nExecuting command as folder is identified to be a valid ${YELLOW}git${NC} repository\n"
printf "Repository: ${MAGENTA}$1${NC} " && eval "${@%$1}"
printf "${YELLOW}[Repository]${NC} ${MAGENTA}$1${NC} " && eval "${@%$1}"
fi
else
eval "${@%$1}"
printf "${YELLOW}${YELLOW}[Repository]${NC}${NC} ${MAGENTA}$1${NC} "; eval "${@%$1}"
fi
}

Expand Down
4 changes: 2 additions & 2 deletions beamery/plugins/audit_git_branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ source "${HOME}/.beamery/beamery/pluginsInterface.sh"
# This is useful to identify dead branches

audit_git_branches() {
execute -g $@ "echo ""; git branch -vv";
execute -g $@ "echo ""; git branch -vv; echo ''";

printf "${YELLOW}\nHistorical Branches Data:\n${NC}";
execute -g $@ "echo""; git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/remotes"
execute -g $@ "echo ""; git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/remotes; echo "";"
}
16 changes: 16 additions & 0 deletions beamery/plugins/check_node_package_usage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# Load the main plugins "interface"
source "${HOME}/.beamery/beamery/pluginsInterface.sh"

# check_node_package_usage
# Check the places a certain npm package is used across all the repos

check_node_package_usage() {

execute -n "grep -sw $1 ./package.json >/dev/null && printf '\e[1A\e[40C' && grep -sw '\"$1\":' ./package.json || printf '\e[1A\e[K'"

}



14 changes: 0 additions & 14 deletions beamery/plugins/check_npm_usage.sh

This file was deleted.

5 changes: 1 addition & 4 deletions beamery/plugins/clean_git_local_branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ source "${HOME}/.beamery/beamery/pluginsInterface.sh"

clean_git_local_branches() {


# Check if gawk is installed which is not by default in mac systems
if ! type gawk &> /dev/null ; then
if [[ "$OSTYPE" == "darwin"* ]]; then
Expand All @@ -18,9 +17,7 @@ clean_git_local_branches() {
fi
fi

execute -g $@ "echo""; git fetch --all";
execute -g $@ "echo""; git remote prune origin"
execute -g $@ "echo""; git gc --prune=now"
execute -g $@ "echo""; git fetch --all && git remote prune origin && git gc --prune=now; echo''";

if [[ `git branch -vv | grep ': gone]'` ]]; then
printf "\n${YELLOW}Making sure that all 'gone' branches are also removed ..\n\n${NC}"
Expand Down
2 changes: 1 addition & 1 deletion beamery/plugins/clean_git_remote_branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ source "${HOME}/.beamery/beamery/pluginsInterface.sh"
# Clean remote branches that have been merged into master and delete them from remotes as well

clean_git_remote_branches() {
execute -g $@ "echo""; git branch -r --merged | egrep -v '(^\*|master|development)' | sed 's/origin\///g'| xargs -n 1 git push --delete origin"
execute -g $@ "echo""; git branch -r --merged | egrep -v '(^\*|master|development)' | sed 's/origin\///g'| xargs -n 1 git push --delete origin; echo ''"
}
2 changes: 1 addition & 1 deletion beamery/plugins/clean_git_stash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ clean_git_stash() {
read -p "Are you sure you want to proceed ? [Y/N] " -n 1;

if [[ $REPLY =~ ^[Yy]$ ]]; then
execute -g $@ "git stash clear && echo '--> done'"
execute -g $@ "echo ''; git stash clear && echo '--> done'"
fi
echo "";
}
16 changes: 14 additions & 2 deletions beamery/plugins/clean_npm_modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,27 @@ source "${HOME}/.beamery/beamery/pluginsInterface.sh"

clean_npm_modules() {

check_npm_report() {
if [[ -f "npm-report.txt" ]]; then
read -p "We have detected that an npm-clean-report already exists. Would you like to clear that out before ? [Y/N] " -n 1;
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf "npm-clean-report.txt"
echo ""
fi;
fi;
}

if [[ $@ == *'-s'* ]]; then
echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands"
else
if command_exists npm-clean ; then
execute -n $@ "npm-clean >> ../npm-clean-report.txt"
check_npm_report
execute -n 'echo "Cleaning NPM modules in package.json"; echo [REPOSITORY] `basename $PWD` >> ../npm-clean-report.txt; npm-clean >> ../npm-clean-report.txt'
else
printf 'npm-check module was not found. Installing now:';
npm install -g npm-clean
execute -n $@ "npm-clean >> ../npm-clean-report.txt"
check_npm_report
execute -n 'echo "Cleaning NPM modules in package.json"; echo [REPOSITORY] `basename $PWD` >> ../npm-clean-report.txt; npm-clean >> ../npm-clean-report.txt'
fi
fi;
}
17 changes: 15 additions & 2 deletions beamery/plugins/generate_npm_report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,28 @@ source "${HOME}/.beamery/beamery/pluginsInterface.sh"

generate_npm_report() {

check_npm_report() {
if [[ -f "npm-report.txt" ]]; then
read -p "We have detected that an npm-report already exists. Would you like to clear that out before ? [Y/N] " -n 1;
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf "npm-report.txt"
echo ""
fi;
fi;
}

if [[ $@ == *'-s'* ]]; then
echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands"
else
if command_exists npm-check ; then
execute -n "npm-check >> ../npm-report.txt"
check_npm_report
execute -n 'echo "Checking NPM modules in package.json"; echo [REPOSITORY] `basename $PWD` >> ../npm-report.txt; npm-check >> ../npm-report.txt'
else
printf 'npm-check module was not found. Installing now:';
npm install -g npm-check
execute -n "npm-check >> ../npm-report.txt"
check_npm_report
execute -n 'echo "Checking NPM modules in package.json"; echo [REPOSITORY] `basename $PWD` >> ../npm-report.txt; npm-check >> ../npm-report.txt'
fi
fi;
}

2 changes: 1 addition & 1 deletion beamery/plugins/list_git_active_branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ source "${HOME}/.beamery/beamery/pluginsInterface.sh"
# This is useful to know which branches are flipped on which repos

list_git_active_branch() {
execute -g $@ printf "'${YELLOW}' && git branch | grep '^\*' | cut -d' ' -f2 && printf '${NC}'"
execute -g $@ printf "'\e[1A\e[70CBranch: ${YELLOW}' && git branch | grep '^\*' | cut -d' ' -f2 && printf '${NC}'"
}
5 changes: 2 additions & 3 deletions beamery/plugins/switch_git_branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ switch_git_branch() {
if [[ $REPLY =~ ^[Yy]$ ]]; then
if ! [[ $BRANCH =~ ^(master|development)$ ]]; then
printf "\nYou are switching to a non-default branch ... fetching first\n"
execute -g "git fetch; git stash; git checkout $BRANCH"
execute -g "echo''; git fetch; git stash; git checkout $BRANCH; echo''"
else
execute -g "git stash; git checkout $BRANCH"
execute -g "echo''; git stash; git checkout $BRANCH; echo''"
fi
fi;
echo "";
fi;
}
6 changes: 2 additions & 4 deletions beamery/plugins/switch_git_branch_and_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ switch_git_branch_and_update() {
printf "\nYou are switching to a non-default branch ... will fetch repositories first\n"
# Since this function already accepts params passed
# We need to check if any of the params passed is the -s which indicates this should run on a single folder
execute -g "git fetch; git stash; git checkout $BRANCH; git pull $REMOTE $BRANCH"
execute -g "echo ''; git fetch; git stash; git checkout $BRANCH; git pull $REMOTE $BRANCH; echo ''"
else
execute -g "git stash; git checkout $BRANCH; git pull $REMOTE $BRANCH"
execute -g "echo ''; git stash; git checkout $BRANCH; git pull $REMOTE $BRANCH; echo''"
fi
fi;
echo "";
fi;

}
2 changes: 1 addition & 1 deletion beamery/plugins/track_all_remote_git_branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source "${HOME}/.beamery/beamery/pluginsInterface.sh"
# Track all remote branches that are not being tracked locally

track_all_remote_git_branches() {
execute -g $@ git branch -r | grep -v '\->' | while read remote; do git branch --track ${remote#origin/} $remote > /dev/null; done
execute -g $@ "git branch -r | grep -v '\->' | while read remote; do git branch --track ${remote#origin/} $remote > /dev/null; done;"
echo "--> All remote branches tracked"
}

2 changes: 1 addition & 1 deletion beamery/plugins/update_git_branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ update_git_branch() {
if [[ $@ == *'-s'* ]]; then
echo "This function is not designed to work in single folder mode .. please revert to good old fashioned commands"
else
execute -g "git pull ${2:-origin} ${1:-master}"
execute -g "echo''; git pull ${2:-origin} ${1:-master}; echo''"
fi;
}
6 changes: 3 additions & 3 deletions beamery/pluginsInterface.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ execute() {
if [[ $IS_NODE_FOLDER = 1 ]]; then
if [ -f "package.json" ]; then
[ $IS_SHOW_FOLDER_TYPE = 1 ] && printf "\nExecuting command as folder is identified to contain valid ${YELLOW}Node.js${NC} code\n"
printf "Repository: ${MAGENTA}$1${NC} "; eval "${@%$1}"
printf "${YELLOW}[Repository]${NC} ${MAGENTA}$1${NC}\n"; eval "${@%$1}"
fi
elif [[ $IS_GIT_FOLDER = 1 ]]; then
if [ -f ".git/config" ]; then
[ $IS_SHOW_FOLDER_TYPE = 1 ] && printf "\nExecuting command as folder is identified to be a valid ${YELLOW}git${NC} repository\n"
printf "Repository: ${MAGENTA}$1${NC} "; eval "${@%$1}"
printf "${YELLOW}[Repository]${NC} ${MAGENTA}$1${NC}\n"; eval "${@%$1}"
fi
else
eval "${@%$1}"
printf "${YELLOW}[Repository]${NC} ${MAGENTA}$1${NC}\n"; eval "${@%$1}"; echo ""
fi
}

Expand Down
Loading

0 comments on commit a4f1db7

Please sign in to comment.