Last active
April 8, 2025 18:23
-
-
Save QinMing/ed6fefd6ab2929224ec48d05933c600c to your computer and use it in GitHub Desktop.
my very own zshrc
This file contains hidden or 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
# Copyright (c) 2016-2021 Ming Qin (覃明) <https://github.com/QinMing> | |
# Open source under MIT LICENSE. | |
export PATH=/usr/local/bin:$PATH | |
export ZSH="$HOME/.oh-my-zsh" | |
# Make history-substring-search case sensitive, for history-substring-search plugin | |
HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS="" | |
DISABLE_MAGIC_FUNCTIONS=true | |
# So that it doesn't add the extra excape character. Without this line, pasting `mingq.in/?param` will become `mingq.in/\?param` | |
ZSH_THEME="agnoster" | |
# Install fonts here https://github.com/powerline/fonts | |
plugins=(history-substring-search git pip docker docker-compose) | |
source $ZSH/oh-my-zsh.sh | |
### end of zsh configuration ### | |
unsetopt AUTO_CD | |
# AUTO_CD: if the command isn't found in the current directory, the shell will automatically cd into the command name, if the directory is found. | |
alias gw=./gradlew | |
alias gradlew=./gradlew | |
# compdef gw=gradle | |
# https://github.com/gradle/gradle-completion/issues/14#issuecomment-478816232 | |
alias l='ls -alhtr' | |
alias upthis='ss u' | |
alias downthis='ss d' | |
alias dcp='docker-compose' | |
alias docker-clean='docker system prune --volumes -f' | |
alias tff='find ./*/infrastructure -maxdepth 0 | xargs -L 1 tf fmt' | |
alias g='git' | |
alias gs='git s' | |
alias gsp="git stash pop" | |
alias gl='git l' | |
alias gd='git d' | |
alias gb='git b' | |
alias gck='git ck' | |
alias gp='git p' | |
# https://stackoverflow.com/questions/1904860/how-to-remove-unreferenced-blobs-from-my-git-repo | |
alias git-clean='git -c gc.reflogExpire=0 -c gc.reflogExpireUnreachable=0 -c gc.rerereresolved=0 -c gc.rerereunresolved=0 -c gc.pruneExpire=now gc "$@"' | |
unalias gbd || true # remove oh-my-zsh built-in gbd | |
gbd() { | |
# Delete local branches that merged (or squash-merged) to default branch. | |
# Args: | |
# $1: (Optional) name of the default branch, if not either `main` or `master` | |
# Note: | |
# Forked from https://github.com/not-an-aardvark/git-delete-squashed | |
local mainBranch mergeBase | |
if [ -z "$1" ]; then | |
git show-ref --verify --quiet refs/heads/main | |
[ $? -eq 0 ] && mainBranch=main || mainBranch=master | |
else | |
mainBranch=$1 | |
fi | |
git checkout -q $mainBranch && | |
git fetch --tags -f --prune origin && | |
git merge --ff-only origin/$mainBranch && | |
echo "Deleting merged branches:" && | |
git branch --merged | grep -v '*' | grep -q . && git branch --merged | grep -v '*' | xargs -n 1 git branch -d || echo "(No merged branches to delete)" && | |
echo "Deleting squash-merged branches:" && | |
git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do | |
mergeBase=$(git merge-base $mainBranch $branch) && | |
[[ $( | |
git cherry $mainBranch $( | |
git commit-tree $( | |
git rev-parse $branch^{tree} | |
) -p $mergeBase -m _ | |
) | |
) == "-"* | |
]] && git branch -D $branch; | |
done; | |
git prune | |
} | |
lazy_load() { | |
# Act as a stub to another shell function/command. When first run, it will load the actual function/command then execute it. | |
# E.g. This made my zsh load 0.8 seconds faster by loading `nvm` when "nvm", "npm" or "node" is used for the first time | |
# $1: space separated list of alias to release after the first load | |
# $2: file to source | |
# $3: name of the command to run after it's loaded | |
# $4+: argv to be passed to $3 | |
echo "Lazy loading $1 ..." | |
# $1.split(' ') using the s flag. In bash, this can be simply ($1) #http://unix.stackexchange.com/questions/28854/list-elements-with-spaces-in-zsh | |
# Single line won't work: local names=("${(@s: :)${1}}"). Due to http://stackoverflow.com/questions/14917501/local-arrays-in-zsh (zsh 5.0.8 (x86_64-apple-darwin15.0)) | |
local -a names | |
if [[ -n "$ZSH_VERSION" ]]; then | |
names=("${(@s: :)${1}}") | |
else | |
names=($1) | |
fi | |
unalias "${names[@]}" | |
. $2 | |
shift 2 | |
$* | |
} | |
group_lazy_load() { | |
local script | |
script=$1 | |
shift 1 | |
for cmd in "$@"; do | |
alias $cmd="lazy_load \"$*\" $script $cmd" | |
done | |
} | |
export NVM_DIR=~/.nvm | |
group_lazy_load $HOME/.nvm/nvm.sh nvm node npm npx truffle gulp yarn | |
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting | |
group_lazy_load $HOME/.rvm/scripts/rvm rvm irb rake rails | |
unset -f group_lazy_load | |
# simple python virtual environment wrapper | |
alias ve="lazy_load 've' $HOME/git/simple-virtualenv-wrapper/ve.sh ve" | |
# If using GnuPG to sign git commits, etc, need the following. | |
export GPG_TTY=$(tty) | |
export AUTOSUGGESTION_HIGHLIGHT_COLOR='fg=cyan' # water mark for history commands | |
# Generated by hashicorp vault | |
# autoload -U +X bashcompinit && bashcompinit | |
# complete -o nospace -C /usr/local/bin/vault vault | |
# Other applications | |
# eval $(thefuck --alias) | |
# eval "$(pyenv init -)" | |
# export PIPENV_PYTHON=$HOME/.pyenv/shims/python | |
# export VIRTUALENV_PYTHON=$HOME/.pyenv/shims/python | |
# # The new version of pyenv asked for these 3 lines | |
# export PYENV_ROOT="$HOME/.pyenv" | |
# export PATH="$PYENV_ROOT/bin:$PATH" | |
# eval "$(pyenv init --path)" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment