Last active
November 17, 2022 21:53
-
-
Save gusaiani/70736c970c2b2d4020006eb7dd31bc40 to your computer and use it in GitHub Desktop.
ZSH Initializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkcd() { | |
dir="$*" | |
mkdir -p "$dir" && cd "$dir" | |
} | |
cpwd() { | |
pwd | pbcopy | |
} | |
alias gcne='git commit --amend --no-edit' | |
# Git delete all merged branches | |
alias gdmb='git branch --merged main | grep -v main | xargs -I % sh -c "git branch -d %; git push -d origin %;"' | |
alias gap='git add -p' | |
alias ap='gap' | |
unalias gcm | |
gcm() { | |
local has_main=$(git branch --list main) | |
if [[ -z ${has_main} ]]; then | |
git checkout master | |
else | |
git checkout main | |
fi | |
} | |
# Git Sync with Master: from master branch, pull, and delete all merged branches locally and remotely | |
alias gsm='gcm;gl;gdmb;git remote prune origin;' | |
alias sm='gsm' | |
alias st='git status' | |
p() { | |
if [[ $(git checkout) ]]; then | |
gp | |
else | |
git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD) | |
fi | |
} | |
alias gpu='git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD)' | |
alias gpuo='gpu;go' | |
alias gpff='git push --force' | |
alias gpf='git push --force-with-lease' | |
alias pf='gpf' | |
alias gpsm='git push staging master' | |
alias go='git open' | |
alias o='git open' | |
# Git stage all deleted | |
alias gsd='git rm $(git ls-files --deleted)' | |
# Git fetch upstream and merge to master | |
gfu() { | |
git fetch upstream | |
git merge upstream/master | |
} | |
alias gt='git checkout --track' | |
alias gphm='git push heroku master' | |
alias glp='git log -p' | |
alias gln='git log --name-only' | |
alias gc='git clone' | |
gcamp() { | |
git add . | |
str="$*" | |
gcam "$str" | |
gp | |
} | |
alias a.='ga .' | |
alias a='ga' | |
alias ©='gcamp' | |
†() { | |
str="$*" | |
gcamp "$str" | |
} | |
alias grm='git rebase master' | |
alias grc='git rebase --continue' | |
alias gra='git rebase --abort' | |
alias grao='git remote add origin' | |
alias uc='git commit -m "Update Changelog"' | |
alias ucp='uc;gp' | |
alias gucp='guc;gp' | |
# Remove all local branches except master | |
alias remove_all_local_branches_except_master='git branch | grep -v "master\|main" | xargs git branch -D ' | |
b() { | |
if [ $# -eq 0 ] | |
then | |
git branch | |
else | |
gco -b $* | |
fi | |
} | |
# git commit -m | |
c() { | |
if [ $# -eq 0 ] | |
then | |
git commit | |
else | |
str="$*" | |
git commit -m "$str" | |
fi | |
} | |
# Grep for string in list of branches and git checkout a find | |
ggc() { | |
gco $(gb | grep $1) | |
} | |
gto() { | |
branch="$*" | |
git checkout --track origin/"$branch" | |
} | |
# Copy current branch name to clipboard | |
ccb() { | |
git branch | grep \* | cut -d ' ' -f2 | pbcopy | |
} | |
# Go to branch via fzf | |
fb() { | |
git branch | fzf | xargs git checkout | |
} | |
alias pc='gh pr create' | |
alias opr='hub pr show' | |
alias pro='hub pr show' | |
alias h='heroku' | |
alias ho='heroku open' | |
# NPM | |
alias ns='npm start' | |
alias ni='npm i' | |
alias nis='npm i --save' | |
alias nt='npm test' | |
alias nta='npm run test-all' | |
# Yarn | |
alias y='yarn' | |
alias yi='yarn install' | |
alias ys='yarn start' | |
alias yd='yarn dev' | |
alias ya='yi;ys' | |
alias yo='yarn outdated' | |
alias u='yvm use' | |
alias ytw='yarn test --watch' | |
alias tw='yarn test --watch' | |
alias ytd='yarn test:debug:watch' | |
alias cc='yarn check:code' | |
alias ytu='yarn test -u' | |
alias yad='yarn add --dev' | |
alias yl='yarn lint' | |
alias yv='yarn validate' | |
alias e2er='y test:e2e:run' | |
# Jest | |
alias j='jest' | |
# Rspec and notify done | |
nrspec() { | |
path="$*" | |
rspec "$path" && notify_done; | |
} | |
# alias rs='rails server -b 0.0.0.0' | |
alias fs='foreman start' | |
# Run Rubocop on non-deleted, .rb files that are different in your branch from master | |
alias rcf='git diff-tree -r --no-commit-id --name-only head origin/master | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs rubocop' | |
# Run Rubocop on non-deleted, .rb files that are different in your branch from master | |
alias scf='git diff-tree -r --no-commit-id --name-only head origin/master | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs rspec' | |
alias rspec='bundle exec rspec' | |
# Ksdiff recipes | |
alias ksde='ksdiff ~/code/open-source/elixir/source ~/code/open-source/elixir/clone' | |
# Vim | |
alias v='vim' | |
alias vv='vim .' | |
alias virc='vim ~/.vimrc' | |
alias vpi='v +PlugInstall' | |
alias vpu='v +PlugUpdate' | |
alias vpc='v +PlugClean' | |
# Ip | |
alias ip="dig +short myip.opendns.com @resolver1.opendns.com." | |
alias localip="ipconfig getifaddr en0" | |
# oh-my-zsh config | |
z() { | |
vim ~/.oh-my-zsh/custom/plugins/gusaiani/gusaiani.plugin.zsh | |
} | |
li() { | |
if [ -f firebase.json ]; then | |
yarn lint:js;yarn lint:deps | |
else | |
yarn lint | |
fi | |
} | |
t() { | |
if [ -f mix.exs ]; then | |
mix test "$@" | |
elif [ -f Gemfile.lock ]; then | |
rspec "$@" | |
elif [ -d __pycache__ ]; then | |
pytest "$@" | |
else | |
yarn test "$@" | |
fi | |
} | |
s() { | |
blacktab | |
# metabase | |
if [ -f webpack.static-viz.config.js ]; then | |
NODE_OPTIONS="--max-old-space-size=8096" yarn dev-ee | |
elif [ -f manage.py ]; then | |
manage.py runserver | |
elif [ -f mix.exs ]; then | |
iex -S mix phx.server | |
elif [ -f elm-package.json ]; then | |
elm-live --port=3000 --output=elm.js src/Main.elm --pushstate --open --debug | |
elif [ -f Gemfile.lock ]; then | |
foreman start | |
elif [ -f default.hbs ]; then | |
yarn watch | |
elif [ -d .next ]; then | |
yarn dev | |
elif [ -f firestore.indexes.json ]; then | |
firebase serve --only functions | |
elif [ -f Cargo.toml ]; then | |
cargo run | |
else | |
yarn start | |
fi | |
} | |
td() { | |
t; | |
OUT=$? | |
if [ $OUT -eq 0 ]; then | |
say "Tests passed" | |
else | |
say "Failure in tests" | |
fi | |
} | |
# Cypress | |
co() { | |
if [ -f webpack.static-viz.config.js ]; then | |
yarn test-cypress-open | |
else | |
npx cypress open | |
fi | |
} | |
alias cr='npx cypress run' | |
alias cdee='cd ~/code/estudo/elixir' | |
alias cdos='cd ~/code/open-source' | |
alias es='cd ~/code/open-source/elixir/source' | |
alias ec='cd ~/code/open-source/elixir/clone' | |
alias e='cd ~/code/open-source/elixir/' | |
alias cdce='cd ~/code/estudo/elixir/cracking-interview-elixir' | |
alias cdcj='cd ~/code/estudo/js/js-cracking-coding-interview' | |
alias q='cd ~/code/estudo/quantum' | |
alias re='cd ~/code/open-source/react' | |
alias res='cd ~/code/open-source/react/source' | |
alias rec='cd ~/code/open-source/react/clone' | |
alias hr='cd ~/code/estudo/js/hacker-rank' | |
alias hre='cd ~/code/estudo/elixir/hacker_rank' | |
alias hrr='cd ~/code/estudo/ruby/hacker_rank' | |
alias hrp='cd ~/code/estudo/python/hacker_rank' | |
alias lc='cd ~/code/estudo/js/leetcode' | |
alias egg='cd ~/code/estudo/elixir/pragstudio/getaways/backend' | |
alias di='cd ~/Documents/Gustavo\ Saiani/.j;vim "+ normal G $" README.md' | |
alias ac='cd ~/Documents/acoes-bovespa && vim +1 empresas.txt' | |
alias san='cd ~/code/security-analysis-graham-dodd && vim "+ normal G $" chapter-43.md' | |
alias gsw='cd ~/code/gustavosaiani.com' | |
alias gsbl='cd ~/code/blog.gustavosaiani.com/wp-content/themes/gusaiani' | |
alias bs='bin/setup -v' | |
alias bu='bundle update' | |
alias bi='bundle install' | |
alias mted='MIX_ENV=test mix ecto.drop' | |
alias hism='heroku run "POOL_SIZE=2 iex -S mix"' | |
alias er='~/code/estudo/js/kent-dodds/epic-react/testing-react-apps' | |
alias in='~/code/index/index-assessment' | |
ti() { | |
cd ~/code/travels-in-italy | |
vim -c 'windo execute "norm! G" | winc h' -O travels-in-italy-de.md travels-in-italy-pt.md | |
} | |
lp() { | |
cd ~/code/little-prince | |
vim -c 'windo execute "norm! G" | winc h' -O petit-prince-ru.md petit-prince-fr.md | |
} | |
pp() { | |
cd ~/code/pragmatic-programmer-russian | |
vim -c 'windo execute "norm! G" | winc h' -O pragmatic-programmer-ru.md pragmatic-programmer-en.md | |
} | |
# Gist | |
# uzg - Update Zsh Gist | |
alias uzg='gist -u 70736c970c2b2d4020006eb7dd31bc40 /Users/gustavosaiani/.oh-my-zsh/custom/plugins/gusaiani/gusaiani.plugin.zsh' | |
alias uvg='gist -u 82efd3fab81e416c6830782a408b5514 ~/.vimrc' | |
alias uzrg='gist -u 96b2f5ae47dcc003e60b52b5be9dcbe5 ~/.zshrc' | |
alias gistup='uzg;uvg;uzrg' | |
# Update Keyboard Maestro Repository | |
uk() { | |
cd ~/.keyboard-maestro-macros | |
gcamp "…More" | |
- | |
} | |
tabcolor() { | |
echo -e -n "\033]6;1;bg;red;brightness;$1\a" | |
echo -e -n "\033]6;1;bg;green;brightness;$2\a" | |
echo -e -n "\033]6;1;bg;blue;brightness;$3\a" | |
} | |
alias p3='python3' | |
blacktab() { | |
tabcolor 0 0 0 | |
} | |
# Formatted, syntax-highlighted cat | |
# brew install bat | |
# https://github.com/sharkdp/bat#installation | |
alias cat='bat' | |
# Nicer looking ls | |
# https://github.com/supercrabtree/k | |
alias l='k -A -h' | |
alias n='node' | |
alias ag='ag --path-to-ignore ~/.agignore' | |
alias mb='cd ~/code/metabase/metabase' | |
alias mbh='cd ~/code/metabase/handbook' | |
alias mif='cd ~/code/metabase/infra-frontend' | |
jdk() { | |
version=$1 | |
export JAVA_HOME=$(/usr/libexec/java_home -v"$version"); | |
java -version | |
} | |
# alias j12="export JAVA_HOME=`/usr/libexec/java_home -v 12`; java -version" | |
# alias j11="export JAVA_HOME=`/usr/libexec/java_home -v 11`; java -version" | |
# alias j10="export JAVA_HOME=`/usr/libexec/java_home -v 10`; java -version" | |
# alias j9="export JAVA_HOME=`/usr/libexec/java_home -v 9`; java -version" | |
# alias j8="export JAVA_HOME=`/usr/libexec/java_home -v 1.8`; java -version" | |
# alias j7="export JAVA_HOME=`/usr/libexec/java_home -v 1.7`; java -version" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment