-
-
Save gatspy/331247284fa7c2f7f121e4a80b783139 to your computer and use it in GitHub Desktop.
.zshrc (ZSH lazy load)
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 Ming Qin (覃明) <https://github.com/QinMing> | |
# Open source under MIT LICENSE. | |
alias l="ls -alht" | |
alias upthis="ss u" | |
alias downthis="ss d" | |
alias g="git" | |
alias gs="git status" | |
alias gl="git l" | |
alias gd="git diff" | |
alias gb="git branch" | |
alias gp="git pull" | |
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 | |
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 | |
alias ve="lazy_load 've' $HOME/git/simple-virtualenv-wrapper/ve.sh ve" | |
alias makedocker=". '/Applications/Docker/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh'" | |
#eval "$(docker-machine env default)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment