Skip to content

Instantly share code, notes, and snippets.

@lbland94
Last active December 14, 2018 16:52
Show Gist options
  • Select an option

  • Save lbland94/9f5a82bd7cb099e3cd7c33464adf8820 to your computer and use it in GitHub Desktop.

Select an option

Save lbland94/9f5a82bd7cb099e3cd7c33464adf8820 to your computer and use it in GitHub Desktop.
A few bash helper functions for development to facilitate running commands across multiple projects. Include in ~/.bashrc .

Example usage:

proj start aem ui pds

  • This will run the start scripts for the aem, ui, and pds projects.

proj checkout develop aem ui pds

  • Checks out the develop branch in the specified projects.

proj checkout -b feature/new-branch aem ui pds

  • Checks out or creates feature/new-branch on the specified projects

proj run "git symbolic-ref --short HEAD" aem ui pds

  • Runs the specified command (git symbolic-ref --short HEAD, prints the current branch name) on the specified projects.
PROJECTS=/Users/lbland/Documents/VSCode/projects
IWEB=$PROJECTS/iweb
AEM=$IWEB/aem-www
UI=$IWEB/www-ui
PDS=$IWEB/www-style-guide
API=$IWEB/www-api
proj() {
case "$1" in
start)
for arg in "${@:2}"; do
case "$arg" in
$AEM|AEM|aem)
echo "starting AEM"
newtab "cd $AEM; aem-server start; aem-server log"
;;
$UI|UI|ui)
echo "starting UI"
newtab "cd $UI; git pull; npm run dev"
;;
$PDS|PDS|pds)
echo "starting PDS"
newtab "cd $PDS; git pull; npm run dev"
newtab "cd $PDS; npm run serve"
;;
$API|API|api)
echo "starting API"
newtab "cd $API; git pull; npm run build && npm run start"
;;
*)
echo $arg is not a project
;;
esac
done
;;
fuzzy)
search=$2
dir=$(pwd)
for arg in "${@:3}"; do
case "$arg" in
$AEM|AEM|aem)
echo "searching $search in AEM"
cd $AEM && git fuzzy-search $search
;;
$UI|UI|ui)
echo "searching $search in UI"
cd $PDS && git fuzzy-search $search
;;
$PDS|PDS|pds)
echo "searching $search in PDS"
cd $PDS && git fuzzy-search $search
;;
$API|API|api)
echo "searching $search in API"
cd $API && git fuzzy-search $search
;;
*)
echo $arg is not a project
;;
esac
done
cd "$dir"
;;
checkout)
branch=$2
create=false
if [ "$branch" = "-b" ]; then
branch="$3"
create=true
set -- "${@:1:1}" "${@:3}"
fi
dir=$(pwd)
for arg in "${@:3}"; do
case "$arg" in
$AEM|AEM|aem)
echo "checking out $branch on AEM"
cd $AEM && git checkout "$branch" || $create && git checkout -b "$branch"
;;
$UI|UI|ui)
echo "checking out $branch on UI"
cd $PDS && git checkout "$branch" || $create && git checkout -b "$branch"
;;
$PDS|PDS|pds)
echo "checking out $branch on PDS"
cd $PDS && git checkout "$branch" || $create && git checkout -b "$branch"
;;
$API|API|api)
echo "checking out $branch on API"
cd $API && git checkout "$branch" || $create && git checkout -b "$branch"
;;
*)
echo $arg is not a project
;;
esac
done
cd "$dir"
;;
run)
command="$2"
dir=$(pwd)
for arg in "${@:3}"; do
case "$arg" in
$AEM|AEM|aem)
echo "running $command on AEM"
cd $AEM && $command
;;
$UI|UI|ui)
echo "running $command on UI"
cd $UI && $command
;;
$PDS|PDS|pds)
echo "running $command on PDS"
cd $PDS && $command
;;
$API|API|api)
echo "running $command on API"
cd $API && $command
;;
*)
echo $arg is not a project
;;
esac
done
cd "$dir"
;;
*)
echo $1 is not a valid command
;;
*)
echo $1 is not a valid command
;;
esac
}
newtab() {
osascript -e 'tell application "Terminal" to activate' -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' -e 'tell application "Terminal" to do script "'"$*"'" in selected tab of the front window'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment