Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cjoshmartin/da075a051d6c537dfdccccb170b05d99 to your computer and use it in GitHub Desktop.
Save cjoshmartin/da075a051d6c537dfdccccb170b05d99 to your computer and use it in GitHub Desktop.
shopt -s extglob
alias ll='ls -la'
alias redis='cd ~; redis-server /usr/local/etc/redis.conf'
alias ll_bower='ls -la bower_components'
# gits!
alias gfa="git fetch --all; gs"
# alias grh='git reset --hard; gl 10; gs'
#########################################################################
# misc
#########################################################################
for d in ~/work/*/ ; do
repo=$(basename $d)
eval "bac_$repo() { __buildAndCopy $repo; }"
eval "cd_$repo() { __changeDir ~/work/$repo; gs; }"
#eval "cp_$repo() { __copyBowerComponent $repo; }"
eval "db_$repo() { __debuggingComponent $repo; }"
eval "gf_$repo() { __grunt_force_dir $repo; }"
#eval "link_$repo() { __sym_link $repo; }"
#eval "unlink_$repo() { __sym_unlink $repo; }"
eval "code_$repo() { code ~/work/$repo; }"
#eval "rb_$repo() { __del_bower_dir ~/work/$repo; }"
done
for d in ~/projects/*/ ; do
repo=$(basename $d)
eval "cd_$repo() { __changeDir ~/projects/$repo; gs; }"
eval "code_$repo() { code ~/projects/$repo; }"
done
_bashprofile () {
#subl ~/.bash_profile
code ~/.bash_profile
}
# build and copy bower components to current app directory
__buildAndCopy () {
local currentDir=${PWD##*/};
local dist=~/work/$1/dist;
if [ -d "$dist" ]; then
#element
section "Building: $1";
cd ~/work/$1;
grunt --force;
section "Copying element: $1";
local source=~/work/$1/dist;
local dest=~/work/$currentDir/bower_components/$1/dist;
else
#block
section "Copying block: $1";
local source=~/work/$1;
local dest=~/work/$currentDir/bower_components/$1;
fi
rm -rf $dest;
cp -vR $source $dest;
# section "Building: $currentDir";
cd ~/work/$currentDir;
# grunt --force;
}
__debuggingComponent () {
__buildAndCopy $1
gf;
ns;
}
__changeDir () {
cd $1
if [[ -f .nvmrc && -r .nvmrc ]]; then
nvm use
else
nvm use 4
fi
}
# __copyBowerComponent () {
# rm -rf ./bower_components/$1/dist
# cp -vR ~/work/$1/dist ./bower_components/$1/dist
# }
__grunt_force_dir () {
section "grunt --force (in $1)"
current=${PWD##*/}
cd ~/work/$1
grunt --force
cd ~/work/$current
}
# __sym_link () {
# if [[ $# = 0 ]]; then
# section "__sym_link needs a repo"; return;
# fi
# if [ -d ~/work/$1/dist ]; then
# # mv ./bower_components/$1/dist ./bower_components/$1/dist_old;
# section \
# "rm -rf ./bower_components/$1/dist" \
# "ln -s ~/work/$1/dist ./bower_components/$1/dist";
# rm -rf ./bower_components/$1/dist;
# ln -s ~/work/$1/dist ./bower_components/$1/dist; #ln -s dir link_name
# else
# #assume block
# section \
# "rm -rf ./bower_components/$1;" \
# "ln -s ~/work/$1 ./bower_components/$1";
# rm -rf ./bower_components/$1;
# ln -s ~/work/$1 ./bower_components/$1
# fi
# ls -lR bower_components | grep ^l;
# }
# __sym_unlink () {
# if [[ $# = 0 ]]; then
# section "__sym_unlink needs a repo"; return;
# fi
# section "rm -rf ./bower_components/$1/dist;"
# rm -rf ./bower_components/$1/dist;
# ls -lR bower_components | grep ^l;
# }
# __del_bower_dir () {
# rm -rf ./bower_components/$1
# echo "Removed $1"
# }
blink ()
{
ls -lR bower_components/* | grep ^l;
}
bremove () {
if [[ $# = 0 ]]; then
echo "Specifiy bower component to remove."
return
fi
section "removing ./bower_components/$1"
rm -rf ./bower_components/$1
}
rm_nodemodules () {
rm -rf ./node_modules;
}
rm_bowercomponents () {
rm -rf ./bower_components;
}
#########################################################################
# git
#########################################################################
git_clone_work () {
read -p "repo name: " -e repo;
read -p "Org: " -e org;
cd ~/work;
git clone [email protected]:hai-nguyen/$repo.git;
cd $repo;
git remote add upstream [email protected]:$org/$repo.git;
git remote add eric [email protected]:egmutza/$repo.git
git remote add sam [email protected]:svarga/$repo.git
git remote add iulian [email protected]:imihai/$repo.git
git remote add rob [email protected]:rhite/$repo.git
git fetch --all
git remote -v
}
gclean () {
git reset HEAD *
git checkout -- bower_components/
rm -rf dist/;
git checkout -- dist/;
rm -rf public-optimized/;
git checkout -- public-optimized/
git checkout -- CHANGELOG.md
git checkout -- builddata.json
git checkout -- doc/
rm -rf npm-debug.log
rm -rf .idea/
gs
}
gpruneaway () {
git branch | grep -v \* | xargs git branch -D
}
bb () {
section "Best Builder"
current=${PWD##*/};
cd ~/work/bestbuilderapp;
grunt --force;
NODE_ENV=development npm start;
cd ~/work/$current
}
build_bb() {
section "Morning build of BB"
cd ~/work/bestbuilderapp;
gonetruemaster;
local now="$(date +%b%d)";
local br=$( tr '[A-Z]' '[a-z]' <<< $now );
git branch -D dev-$br
git checkout -b dev-$br
wipehard;
nbg;
chall built;
}
npm_run_qa () {
NODE_ENV=development npm start;
}
gonetruemaster ()
{
section \
"git reset --hard" \
"git checkout master" \
"git fetch --all" \
"git reset --hard upstream/master"
git reset --hard;
git checkout master;
git fetch --all;
git reset --hard upstream/master;
gs;
}
phoenixdown () {
wipehard;
nbg;
}
review () {
section "review"
git checkout -b temp;
git reset --hard;
git branch -D rev;
git checkout -b rev $1;
git branch -D temp;
echo '-----------------------------------------------------------------';
git log --graph --decorate --oneline --all --max-count 17
}
wipe () {
section "wipe (soft)"
rm -rf !(.git|bower_components|node_modules);
rm -rf .idea;
rm -rf .vscode;
git reset --hard;
echo '-----------------------------------------------------------------';
ls -la;
echo '-----------------------------------------------------------------';
git log --graph --decorate --oneline --all --max-count 17
}
wipehard () {
section "wipe hard"
rm -rf !(.git);
rm -rf .idea;
git reset --hard;
echo '-----------------------------------------------------------------';
ls -la;
echo '-----------------------------------------------------------------';
git log --graph --decorate --oneline --all --max-count 17;
}
chall () {
section "checkpoint (save all)"
local now="$(date +%b%d.%I%M)"
local br=$( tr '[A-Z]' '[a-z]' <<< $now );
git add --all --force;
git commit -m "checkpoint $br: $*";
git branch $br
gs
}
ch () {
section "checkpoint"
local now="$(date +%b%d.%I%M)"
local br=$( tr '[A-Z]' '[a-z]' <<< $now );
git add --all;
git commit -m "checkpoint $br: $*";
git branch $br
gs
}
chamend () {
section "checkpoint amend";
git add --all;
git commit --amend --no-edit;
local now="$(date +%b%d.%I%M)";
local br=$( tr '[A-Z]' '[a-z]' <<< $now );
git branch -D $br;
git branch $br;
gs;
}
ds () {
local now="$(date +%b%d.%I%M)"
local br=$( tr '[A-Z]' '[a-z]' <<< $now );
section \
"git add --all" \
"git commit -m \"[$br] $*\"" \
"git branch $br"
git add --all;
git commit -m "$*";
git branch $br
gs
section \
"git add --all --force" \
"git commit -m \"$*\"" \
"git branch $br"
}
dstart() {
if [ ! -d ".git" ]; then
echo "Dear Hai, this is not a fucken repo. You've misused this function before, and fucked up everything. DON'T FUCK UP AGAIN. You're welcome. Sincerely, yourself.";
return;
fi
section \
"Dev Start starting..."
local now="$(date +%b%d.%I%M)"
local br=$( tr '[A-Z]' '[a-z]' <<< $now );
#save
git checkout -b $branch;
git add --all --force;
git commit -m "$branch";
#fetch
git fetch --all;
#reset
git reset --hard;
git clean -fd;
#dev
git checkout dev;
git reset --hard upstream/master;
section "npm install"
if npm install; then
local npmresult="SUCCESS";
else
local npmresult="FAILURE";
fi
section "bower update"
if bower update; then
local bowerresult="SUCCESS";
else
local bowerresult="FAILURE";
fi
section "grunt"
if grunt; then
local gruntresult="SUCCESS";
else
local gruntresult="FAILURE";
fi;
#committing
section "git add --all --force"
git add --all --force;
section "git commit -m \"message\"";
git commit -m "[$branch] dstart (npm: $npmresult, bower: $bowerresult, grunt: $gruntresult)";
section "git push origin dev --force";
git push origin dev --force;
#status
git status;
git log --graph --decorate --oneline --all --max-count 20;
section \
"dstart done." \
" npm: $npmresult" \
" bower: $bowerresult" \
" grunt: $gruntresult";
}
#########################################################################
# building
#########################################################################
gf () {
section "grunt --force"
grunt --force
}
bgf () {
section "bower update; grunt --force;";
bower update;
grunt --force;
section "bower update; grunt --force; (done)";
}
nbg () {
if [ ! -d ".git" ]; then
echo "Dear Hai, this is not a fucken repo. You've misused this function before, and fucked up everything. DON'T FUCK UP AGAIN. You're welcome. Sincerely, yourself.";
return;
fi
section " npm install; bower update; grunt --force;"
if npm install; then
local npmresult="SUCCESS";
else
local npmresult="FAILURE";
fi
section "bower update;"
if bower update; then
local bowerresult="SUCCESS";
else
local bowerresult="FAILURE";
fi
section "grunt --force;"
grunt --force;
git status;
git log --graph --decorate --oneline --all --max-count 20;
section \
"nbg done." \
" npm: $npmresult" \
" bower: $bowerresult"
}
nbghard () {
section "nbg (hard)"
rm -rf node_modules;
rm -rf bower_components;
nbg;
}
nihard () {
section "npm install (hard)"
rm -rf node_modules;
npm cache clean;
npm install;
}
buhard () {
section "bower update (hard)"
rm -rf bower_components;
bower cache clean;
bower update;
}
build () {
local buildStamp=$( tr '[A-Z]' '[a-z]' <<< $(date +%b%d.%I%M) );
#save
section \
"git add --all --force" \
"git commit -m \"[$buildStamp] before building \"" \
"git branch $br"
git add --all --force;
git commit -m "[$br] $*";
git branch -D $br;
git branch $br;
gs
section \
"git add --all --force" \
"git commit -m \"[$br] $*\"" \
"git branch $br"
section "wipe"
rm -rf !(.git)
rm -rf .idea
ls -la
echo "yo $buildStamp"
}
buildelementforrelease () {
if ([ "$1" == "--help" ]); then
echo ""
echo "Usage: "
echo " buildelementforrelease"
echo ""
echo "Description: "
echo " builds an element for release"
echo ""
else
section \
"git reset --hard" \
"git checkout master" \
"git fetch --all" \
"git reset --hard upstream/master"
git reset --hard
git checkout master
git fetch --all
git reset --hard upstream/master
section \
"rm -rf !(.git|.gitignore)" \
"rm -rf *" \
"git reset --hard"
rm -rf !(.git|.gitignore)
rm -rf *
git reset --hard
code .
read -p "Bump and enter version: " -e elementversion
section \
" rm -rf ./node_modules" \
" npm cache clean" \
" npm install; npm install;"
rm -rf ./node_modules;
npm cache clean;
while ! npm install; do false; done;
npm install;
section \
"rm -rf ./bower_components" \
"bower cache clean" \
"bower update"
rm -rf ./bower_components;
bower cache clean;
while ! bower update; do false; done;
section "grunt"
grunt
section "git status"
git status;
gl 17;
read -p "Everything looks good? (y/n) " -e yn
if [ $yn != "y" ]; then
return
fi
section \
"git add --all" \
"git commit -m \"Release $elementversion\"" \
"git tag -a $elementversion -m \"Tagging $elementversion\"" \
"git push upstream master" \
"git push upstream $elementversion"
git add --all
git commit -m "Release $elementversion"
git tag -a $elementversion -m "Tagging $elementversion"
git push upstream master
git push upstream $elementversion
section "buildelementforrelease done"
fi
}
release () {
section "release";
gs;
read -p "Check: on master brand? ";
read -p "Check: built (npm bower)? ";
read -p "Check: version bumped then grunt? ";
read -p "Version: " -e elementversion;
git add --all;
git commit -m "Release $elementversion";
git tag -a $elementversion -m "Tagging $elementversion";
git push upstream master;
git push upstream $elementversion;
git status;
gl 17
}
buildblockforrelease () {
if ([ "$1" == "--help" ]); then
echo ""
echo "Usage: "
echo " buildblockforrelease"
echo ""
echo "Description: "
echo " builds a block for release"
echo ""
else
section \
"git fetch --all" \
"git reset --hard upstream/master"
git fetch --all
git reset --hard upstream/master
section \
"rm -rf !(.git|.gitignore)" \
"rm -rf *" \
"git reset --hard"
rm -rf !(.git|.gitignore)
rm -rf *
git reset --hard
code .
read -p "Bump (config.js & bower.js) and enter version: " -e elementversion
bw wipe
gs
read -p "Everything looks good? (y/n) " -e yn
if [ $yn != "y" ]; then
return
fi
section \
"git add --all" \
"git commit -m \"Release $elementversion\"" \
"git tag -a $elementversion -m \"Tagging $elementversion\"" \
"git push upstream master" \
"git push upstream $elementversion"
git add --all
git commit -m "Release $elementversion"
git tag -a $elementversion -m "Tagging $elementversion"
git push upstream master
git push upstream $elementversion
section "buildblockforrelease done"
fi
}
####################################################################################################
# git
####################################################################################################
gc () {
# git checkout -- dist/* public-optimized/* bower_components/* doc/*
# git checkout -- CHANGELOG.md builddata.json;
if [[ $# = 0 ]]; then
message="[$(date)]"
else
message="$*"
fi
section \
"git add --all" \
"git commit -m"
git add --all
git commit -m "$message"
gs
}
gl () {
echo '-----------------------------------------------------------------';
if [[ $# = 0 ]]; then
git log --graph --decorate --oneline --all --max-count 25;
else
git log --graph --decorate --oneline --all --max-count $1;
fi
}
gs ()
{
clear;
git status;
gl 17
}
gremotesofteam () {
read -p "Repo name: " -e reponame
git remote add eric [email protected]:egmutza/$reponame.git
git remote add sam [email protected]:svarga/$reponame.git
git remote add iulian [email protected]:imihai/$reponame.git
git remote add rob [email protected]:rhite/$reponame.git
git remote -v
}
#########################################################################
# internals
#########################################################################
section () {
printf "\n"
section_line
for arg in "$@"; do
printf "$arg\n"
done
section_line
printf "\n"
}
section_line () {
start="████"
today=" $(date) "
((x=${#today} + ${#start}))
printf "\e[93m$start\e[0m\e[37m$today\e[0m"
printf "\e[93m"
while [ $x -lt $COLUMNS ]; do
printf "█";
let x=$x+1;
done;
printf "\e[0m\n"
}
#########################################################################
# TMC
#########################################################################
tmcrunlocal () {
section "tmcrunlocal done"
nvm use 0.10
node ~/work/tools/devconnect/app.js -c proxyconfig.js
}
# this is put here last because it fucks up syntax highlighting
bversions () {
toPrint=()
for D in `find ./bower_components -maxdepth 1 -type d`
do
if [ -f $D/.bower.json ]; then
local component="$(sed 's/\.\/bower_components\///g' <<< $D)" # the perpetrator
toPrint+=($component)
local version=`grep "version\"\:" $D/.bower.json | sed 's/\"version\"://g'`
if [ "$version" == "" ]; then
version="N/A"
fi
toPrint+=($version)
fi
done
printf "%-30s %-20s\n" ${toPrint[@]}
}
#########################################################################
# exports - must be last ?
#########################################################################
export PS1='\w$ ' #full path in terminal
export NVM_DIR="/Users/hai.nguyen/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
PATH="/usr/local/opt/[email protected]/libexec/gpgbin:$PATH"
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
PATH=~/Library/Python/3.6/bin:$PATH
export PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment