Skip to content

Instantly share code, notes, and snippets.

@karlhadwen
Last active April 12, 2024 01:56
Show Gist options
  • Save karlhadwen/da7ae3642f4207c46e62e3260f17a1d3 to your computer and use it in GitHub Desktop.
Save karlhadwen/da7ae3642f4207c46e62e3260f17a1d3 to your computer and use it in GitHub Desktop.
.zshrc settings
export ZSH="/Users/karlhadwen/.oh-my-zsh"
export PATH=${PATH}:/usr/local/mysql/bin/
ZSH_THEME="robbyrussell"
ZSH_DISABLE_COMPFIX=true
plugins=(
git
zsh-autosuggestions
last-working-dir
nvm
)
source $ZSH/oh-my-zsh.sh
source /Users/karlhadwen/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# configuration
# custom aliases
alias c="code .";
alias ll="ls -1a";
alias kan="killall node";
alias ..="cd ../";
alias ..l="cd ../ && ll";
alias de="cd ~/Desktop";
alias dd="cd ~/code";
alias d="cd ~/code && cd "
alias show-files='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app'
alias hide-files='defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app'
alias delete-dsfiles="find . -name '.DS_Store' -type f -delete"
alias npm-update="npx npm-check -u";
alias flushdns="sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder"
alias cleandesk="defaults write com.apple.finder CreateDesktop false; killall Finder"
alias messydesk="defaults write com.apple.finder CreateDesktop true; killall Finder"
alias install-eslint="exec 3<&1;bash <&3 <(curl https://raw.githubusercontent.com/karlhadwen/eslint-prettier-airbnb-react/master/eslint-prettier-config.sh 2> /dev/null)"
## git aliases
alias gc="git checkout ";
alias gcm="git checkout master";
alias gs="git status";
alias gpull="git pull";
alias gf="git fetch";
alias gfa="git fetch --all";
alias gf="git fetch origin";
alias gpush="git push";
alias gpushf="git push -f";
alias gd="git diff";
alias ga="git add .";
alias glog="git log";
alias gb="git branch";
alias gbr="git branch remote"
alias gfr="git remote update"
alias gbn="git checkout -B "
alias grf="git reflog";
alias grh="git reset HEAD~" # last commit hard
alias gac="git add . && git commit -a -m "
alias gsu="git gpush --set-upstream origin "
alias glog="git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --branches"
## checkout a new remote branch (exists remote, not locally)
## git checkout -b LocalName origin/remotebranchname (checkout a remote branch)
## npm aliases
alias ni="npm install";
alias nrs="npm run start -s --";
alias nrb="npm run build -s --";
alias nrd="npm run dev -s --";
alias nrt="npm run test -s --";
alias nrtw="npm run test:watch -s --";
alias nrv="npm run validate -s --";
alias rmn="rm -rf node_modules";
alias flush-npm="rm -rf node_modules && npm i && echo NPM is done";
## yarn aliases
alias dev="yarn run dev"; # run dev
## docker
alias di='docker images'
alias drr='docker-compose restart'
alias dup='docker-compose up'
alias dcs='docker-compose stop'
alias dcrm='docker-compose rm'
alias dri='docker rmi -f $(docker images -a -q)'
#kubernetes
alias k='kubectl'
alias kg='kubectl get'
alias kgp='kubectl get pod'
alias kgs='kubectl get services'
alias kgd='kubectl get deployments'
alias kgrs='kubectl get replicaset'
## other aliases
alias zshrc='code ~/.zshrc'
alias topten="history | commands | sort -rn | head"
alias myip="curl http://ipecho.net/plain; echo"
alias dirs='dirs -v | head -10'
alias usage='du -h -d1'
alias update="source ~/.zshrc"
alias sshdir="cd ~/.ssh"
alias runp="lsof -i "
alias md="mkdir "
alias ..='cd ..'
alias ...='cd ../..'
## custom functions
# gpr() {
# if [ $? -eq 0 ]; then
# github_url=`git remote -v | awk '/fetch/{print $2}' | sed -Ee 's#(git@|git://)#http://#' -e 's@com:@com/@' -e 's%\.git$%%'`;
# branch_name=`git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3`;
# pr_url=$github_url"/compare/master..."$branch_name
# open $pr_url;
# else
# echo 'failed to open a pull request.';
# fi
# }
commands() {
awk '{a[$2]++}END{for(i in a){print a[i] " " i}}'
}
# this loads nvm
autoload -U add-zsh-hook
load-nvmrc() {
if [[ -f .nvmrc && -r .nvmrc ]]; then
nvm use
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/karlhadwen/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/karlhadwen/opt/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/karlhadwen/opt/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/Users/karlhadwen/opt/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
export GEM_HOME="$HOME/.gem"
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
@sylviapullom
Copy link

Thank you!

@karlhadwen
Copy link
Author

Thank you!

You're welcome!

@iamsarthakjoshi
Copy link

iamsarthakjoshi commented Sep 2, 2020

Hi Karl,

Running this command: alias topten="history | commands | sort -rn | head";
failed to this: zsh: command not found: commands

Thanks for sharing your cool commands! 👍

@karlhadwen
Copy link
Author

Hi Karl,

Running this command: alias topten="history | commands | sort -rn | head";
failed to this: zsh: command not found: commands

Thanks for sharing your cool commands! 👍

Are you running this on a Mac? Seems to work on my side.

@saksham36
Copy link

@iamsarthakjoshi
Don't forget to include the custom function commands() { awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' } in your .zshrc :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment