Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # General
- export LANG=en_US.UTF-8
- export LC_CTYPE=en_US.UTF-8
- export LC_ALL=en_US.UTF-8
- # Leo's Preferences home folder
- LEO_PREF_PATH=~/leospreferences
- LEO_UNIX_PREF_PATH=$LEO_PREF_PATH/Unix
- # disable ctrl-D closes terminal: http://unix.stackexchange.com/questions/139115/disable-ctrl-d-window-close-in-terminator-terminal-emulator
- set -o ignoreeof
- # default editors
- export EDITOR='nvim'
- export VISUAL='nvim'
- # Path to your oh-my-zsh installation.
- export FZF_HOME=$LEO_UNIX_PREF_PATH/fzf
- export ZSH=$LEO_UNIX_PREF_PATH/\[dot\]oh-my-zsh # DO NOT change variable name "$ZSH" to anything else
- export MANPATH="/usr/local/man:$MANPATH"
- export SSH_KEY_PATH=$HOME/.ssh/dsa_id
- # zsh custom folder
- export ZSH_CUSTOM=$ZSH/custom # DO NOT change "ZSH_CUSTOM" to anything else
- # Set name of the theme to load. Look in ~/.oh-my-zsh/themes/
- # Optionally, if you set this to "random", it'll load a random theme eachtime that oh-my-zsh is loaded.
- ZSH_THEME="bullet-train"
- # 12h mode for zsh's bullet train theme
- BULLETTRAIN_TIME_12HR="true"
- # Disable case sensitive
- CASE_SENSITIVE="false"
- # Disable correction
- ENABLE_CORRECTION="false"
- # Dissplay red dots whilst waiting for completion.
- COMPLETION_WAITING_DOTS="true"
- # History timestamp. The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
- HIST_STAMPS="yyyy-mm-dd"
- # Highlight everything
- ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor)
- ########################################## oh-my-zsh ##############################################
- # Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
- # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
- # Example format: plugins=(rails git textmate ruby lighthouse)
- # Add wisely, as too many plugins slow down shell startup.
- #plugins=(git tmux)
- plugins=(zsh_reload git adb colored-man zsh-syntax-highlighting gradle battery osx)
- # source
- source "$ZSH/oh-my-zsh.sh"
- ##################################################################################################
- ####################################### Leo's configuration #######################################
- ### Leo's own Mac
- # PATHS
- export PATH=$PATH:/Users/leolink/Documents/DevelopmentTools/Android/sdk/platform-tools
- export PATH=$PATH:/Users/leolink/Documents/DevelopmentTools/sdk/tools
- export PATH=$PATH:/usr/local/bin
- export PATH=$PATH:$LEO_PREF_PATH/Git/git-diff-highlight/
- export GROOVY_HOME=/usr/local/opt/groovy/libexec
- # ALIASES
- # Utilities
- alias ll='ls -l'
- alias lla='ls -la'
- alias skype='sudo /Applications/Skype.app/Contents/MacOS/Skype'
- alias fuck='sudo'
- alias ggd="cd ~/Google\ Drive"
- alias leospref="cd $LEO_PREF_PATH"
- alias dropbox='cd ~/Dropbox'
- alias desktop='cd ~/Desktop'
- # VIM
- alias vi='nvim'
- alias vim='nvim'
- alias vimdiff='nvim -d' # E.g. vimdiff file1.java file2.java
- alias vimconf='vi ~/.config/nvim/init.vim'
- # SUBLIME TEXT
- alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"
- # ZSHRC
- alias zconf='vi ~/.zshrc'
- alias zreload='rm -f ~/.zcompdump* & src'
- alias zrestart='exec zsh'
- alias -s txt=vim
- alias -s rb=vim
- alias -s py=vim
- alias -s xml=vim
- alias -s json=vim
- alias -s JSON=vim
- alias -s gradle=vim
- alias -s md=vim
- alias -s java=vim
- alias -s h=vim
- alias -s m=vim
- alias -s c=vim
- alias -s cpp=vim
- # JAVA
- alias javahome='/usr/libexec/java_home -V'
- # TMUX
- # Automatically start a tmux session upon logging in
- #ZSH_TMUX_AUTOSTART="true"
- #ZSH_TMUX_AUTOCONNECT="false"
- #alias tconf='vi ~/.tmux.conf'
- #alias treload='tmux source-file ~/.tmux.conf'
- #alias tkw='tmux kill-window -t' # + name
- #alias tlkeys='tmux list-keys'
- #alias tls='tmux ls'
- #alias tns='tmux new-session -s'
- #alias tas='tmux attach -t' # + name
- #alias tks='tmux kill-session -t' # + name
- # ANDROID
- alias adb_foreground_activity='adb shell dumpsys window windows | grep -E "mCurrentFocus|mFocusedApp"'
- alias adb_kill_app='adb shell am force-stop'
- # Octave
- alias octave=$'/usr/local/octave/3.8.0/bin/octave-3.8.0 --persist --eval \'setenv("GNUTERM","qt")\'' # dollar sign is amazing: http://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings
- # Ruby
- alias workspace-ruby='~/Dropbox/workspace-Ruby'
- # Python
- alias python='python3'
- alias pip='pip3.5'
- # less
- alias less='less -R -s -M +Gg -F -X' # http://stackoverflow.com/questions/1049350/unable-to-make-less-to-indicate-location-in-percentage
- # ag (The Silver Searcher)
- alias ag='ag --pager "less -R"'
- # tig
- # prevent ctrl-y from suspending tig: https://github.com/jonas/tig/issues/214
- stty dsusp undef
- alias tigconf='vi ~/.tigrc'
- # git
- alias gitconf='vi ~/.gitconfig'
- alias ga='git add'
- alias gaa='git add -A'
- alias gs='git status'
- alias gss='tig status'
- alias gl='tig'
- alias gla='tig --all'
- alias gd='git diff'
- alias gdt='git difftool'
- alias gdty='git difftool -y'
- alias gdta='git difftool -y'
- alias gca='git commit --amend'
- alias gcm='git commit -m'
- alias gsno='git show --name-only'
- alias gt='git tag'
- alias gta='git tag -a'
- alias gck='git checkout'
- alias gckb='git checkout -b'
- alias gco='git checkout --ours'
- alias gct='git checkout --theirs'
- alias gbd='git branch -d'
- alias gbD='git branch -D'
- alias gsl='git stash list'
- alias gp='git fetch origin --prune && git merge --ff-only `git rev-parse --abbrev-ref --symbolic-full-name @{u}`' # avoid ugly graph when pull: https://adamcod.es/2014/12/10/git-pull-correct-workflow.html
- function git_history() {
- fzf_res=`ag -g "" | fzf`
- if [ "$fzf_res" ]; then
- tig log $fzf_res
- fi
- }
- alias gh='git_history'
- ### Work's Mac
- # PATHS
- export STUDIO_VM_OPTIONS=$LEO_PREF_PATH/Android\ Studio/studio_for_smooth_font_on_thunderbolt_monitor.vmoptions
- export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk
- export PATH=$PATH:/Users/linh.le/DeveloperTools/android-sdk-macosx/platform-tools
- export PATH=$PATH:/Users/linh.le/DeveloperTools/android-sdk-macosx/tools
- export JAVA_HOME=`/usr/libexec/java_home -v "1.8" -F`
- export JAVA7_HOME=`/usr/libexec/java_home -v "1.7" -F`
- export JAVA8_HOME=`/usr/libexec/java_home -v "1.8" -F`
- launchctl setenv JAVA7_HOME `/usr/libexec/java_home -v "1.7" -F`
- launchctl setenv JAVA8_HOME `/usr/libexec/java_home -v "1.8" -F`
- launchctl setenv ICHIBA_STORE_PASS "device"
- launchctl setenv ICHIBA_ALIAS "gw"
- launchctl setenv ICHIBA_ALIAS_PASS "device"
- export ICHIBA_STORE_PASS="device"
- export ICHIBA_ALIAS="gw"
- export ICHIBA_ALIAS_PASS="device"
- # ALIASES
- alias workspace='cd ~/Workspace'
- alias ws='cd ~/Workspace'
- ###################################################################################################
- ############################################# UPDATE ##############################################
- ## CONSTANTS
- FILE_LAST_UPDATE="$HOME/.zsh-leos-config-last-update"
- UPDATE_INTERVAL=604800 # a week
- ## CHECK
- function should_update_leos_config() {
- if [ ! -f $FILE_LAST_UPDATE ] # if file doesn't exist
- then
- echo "$FILE_LAST_UPDATE doesn't exist!"
- local now=$(date +%s) # get number of seconds since the epoch
- echo $now >> $FILE_LAST_UPDATE
- return 0
- else
- local last_update=$(head -n 1 $FILE_LAST_UPDATE) # get last update
- # validate
- if ! [[ "$last_update" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
- rm -rf $FILE_LAST_UPDATE
- echo "Failed to validate $FILE_LAST_UPDATE, removing it..."
- return 0
- fi
- local now=$(date +%s) # get number of seconds since the epoch
- local elapsed=$(expr $now - $last_update)
- if [ $elapsed -gt $UPDATE_INTERVAL ] # if update is stale
- then
- echo "It's been a while since last update..."
- echo $now > $FILE_LAST_UPDATE
- return 0
- else
- echo "[UPDATE LEO'S TERMINAL APPS]\nNo need to update!"
- return 1
- fi
- fi
- }
- ## UPDATE
- function update_leos_config() {
- # save current directory
- local cwd="$(pwd)"
- # update git's plugins
- tput setaf 1; tput bold; echo "=====>> [UPDATING] Git's plugins..."; tput sgr0
- wget -O "$LEO_PREF_PATH/Git/hub/hub.zsh_completion" "https://raw.githubusercontent.com/github/hub/master/etc/hub.zsh_completion"
- wget -O "$LEO_PREF_PATH/Git/git-diff-highlight/diff-highlight" "https://raw.githubusercontent.com/git/git/master/contrib/diff-highlight/diff-highlight"
- wget -O "$LEO_PREF_PATH/Git/git-diff-highlight/diff-so-fancy" "https://raw.githubusercontent.com/so-fancy/diff-so-fancy/master/diff-so-fancy"
- wget -O "$LEO_PREF_PATH/Git/git-diff-highlight/libexec/diff-so-fancy.pl" "https://raw.githubusercontent.com/so-fancy/diff-so-fancy/master/libexec/diff-so-fancy.pl"
- chmod +x "$LEO_PREF_PATH/Git/git-diff-highlight/diff-highlight"
- chmod +x "$LEO_PREF_PATH/Git/git-diff-highlight/diff-so-fancy"
- chmod +x "$LEO_PREF_PATH/Git/git-diff-highlight/libexec/diff-so-fancy.pl"
- # update fzf
- tput setaf 1; tput bold; echo "=====>> [UPDATING] fzf..."; tput sgr0
- cd $FZF_HOME && git pull && ./install --all
- # update tldr cache
- tput setaf 1; tput bold; echo "\n\n=====>> [UPDATING] tldr's cache..."; tput sgr0
- tldr --update
- if [ $? -eq 0 ]
- then
- echo "tldr's cache updated!"
- fi
- # update oh-my-zsh
- tput setaf 1; tput bold; echo "\n\n=====>> [UPDATING] oh-my-zsh..."; tput sgr0
- upgrade_oh_my_zsh
- # update zsh-syntax-highlighting
- tput setaf 1; tput bold; echo "\n\n=====>> [UPDATING] zsh-syntax-highlighting..."; tput sgr0
- cd "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting"
- git pull
- cd $cwd # cd back to current directory
- # upgrade brew
- tput setaf 1; tput bold; echo "\n\n=====>> [UPDATING] home brew..."; tput sgr0;
- brew update
- brew upgrade
- ## update vim's pathogen's bundles
- tput setaf 1; tput bold; echo "\n\n=====>> [UPDATING] Vim's pathogen's bundles..."; tput sgr0;
- # update Pathogen itself
- echo "Updating $(tput bold)Pathogen$(tput sgr0)..."
- PATHOGEN_UPDATE_URL="https://tpo.pe/pathogen.vim"
- curl -LSso "$HOME/.vim/autoload/pathogen.vim" $PATHOGEN_UPDATE_URL
- if [ $? -eq 0 ]
- then
- echo "Updated successfully from $PATHOGEN_UPDATE_URL"
- fi
- # update bundles
- cd ~/.vim/bundle
- for i in `ls`; do
- echo "\nUpdating $(tput bold)$i$(tput sgr0)..."
- cd "$i"
- git clean -df
- git reset --hard HEAD
- git pull
- # update vim help
- vim -u NONE -c "helptags ./doc" -c q
- cd ..
- done
- # cd back to current directory
- cd $cwd
- ## DONE
- tput setaf 1; tput bold; echo "\n=====>> DONE!!!\nHave a nice day!"; tput sgr0;
- zreload
- }
- if should_update_leos_config
- then
- update_leos_config
- fi
- ## CLEAN UP
- unset FILE_LAST_UPDATE
- unset UPDATE_INTERVAL
- ###################################################################################################
- ########################################## Scripts ################################################
- # Colorful man pages
- export LESS_TERMCAP_mb=$'\E[01;31m'
- export LESS_TERMCAP_md=$'\E[01;31m'
- export LESS_TERMCAP_me=$'\E[0m'
- export LESS_TERMCAP_se=$'\E[0m'
- export LESS_TERMCAP_so=$'\E[01;47;34m'
- export LESS_TERMCAP_ue=$'\E[0m'
- export LESS_TERMCAP_us=$'\E[01;32m'
- export LESS=-r
- # ZSH: Redefine prompt_context for hiding user@hostname
- prompt_context () { }
- # fzf
- [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
- FZF_DEFAULT_COMMAND='ag -g ""' # not using export so vim will use 'find' instead of ag, use ag to respect .gitignore, .hgignore, and svn:ignore
- export FZF_DEFAULT_OPTS='--color=fg:202,hl:118,hl+:82,info:45,pointer:255,prompt:15' # color ref: http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html, customizable properties: "man fzf"
- export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
- # fix FZF's function definition file not found: https://github.com/junegunn/fzf/issues/553
- alias fixfzf='rm -f ~/.zcompdump*'
- # fbr - checkout git branch
- fbr() {
- local branches branch
- branches=$(git branch -vv) &&
- branch=$(echo "$branches" | fzf +m --no-mouse) &&
- git checkout $(echo "$branch" | awk '{print $1}' | sed "s/.* //")
- }
- # fba - checkout git branch (including remote branches)
- fba() {
- local branches branch
- branches=$(git branch --all | grep -v HEAD) &&
- branch=$(echo "$branches" | fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m --no-mouse) &&
- git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
- }
- # fco - checkout git branch/tag
- fco() {
- local tags branches target
- tags=$(
- git tag | awk '{print "\x1b[31;1mtag\x1b[m\t" $1}') || return
- branches=$(
- git branch --all | grep -v HEAD |
- sed "s/.* //" | sed "s#remotes/[^/]*/##" |
- sort -u | awk '{print "\x1b[34;1mbranch\x1b[m\t" $1}') || return
- target=$(
- (echo "$branches"; echo "$tags") |
- fzf-tmux -l30 -- --no-hscroll --ansi +m --no-mouse -d "\t" -n 2) || return
- git checkout $(echo "$target" | awk '{print $2}')
- }
- # fzf + git tag
- fgt() {
- local tags tag
- tags=$(git tag) &&
- tag=$(echo "$tags" | fzf-tmux -d $(( 2 + $(wc -l <<< "$tags") )) +m --no-mouse) &&
- git checkout $(echo "$tag")
- }
- alias gb='fbr'
- alias gba='fba'
- alias gbt='fco'
- alias gt='fgt'
- # hub (https://github.com/github/hub)
- fpath=("$LEO_PREF_PATH/Git/hub/hub.zsh_completion" $fpath)
- autoload -U compinit && compinit
- # Key Binding
- bindkey '^R' fzf-history-widget
- bindkey '^T' fzf-file-widget
- # Update leo's preferences
- function update_leos_preferences() {
- # save current dir
- local cwd="$(pwd)"
- # cd to $LEO_PREF_PATH
- cd $LEO_PREF_PATH
- git remote update # update remote refs: http://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git
- local LEOS_PREF_GIT_LOCAL=$(git rev-parse @)
- local LEOS_PREF_GIT_REMOTE=$(git rev-parse @{u})
- local LEOS_PREF_GIT_BASE=$(git merge-base @ @{u})
- if [ $LEOS_PREF_GIT_LOCAL = $LEOS_PREF_GIT_REMOTE ]; then
- echo "Up-to-date"
- elif [ $LEOS_PREF_GIT_LOCAL = $LEOS_PREF_GIT_BASE ]; then
- git pull
- # only reload if git pull suceeded
- if [ $? -eq 0 ]
- then
- zreload
- else
- git status
- fi
- elif [ $LEOS_PREF_GIT_REMOTE = $LEOS_PREF_GIT_BASE ]; then # TODO: fix this case, sometimes it leads to infinite recursive calls
- git pull
- # only reload if git pull suceeded
- if [ $? -eq 0 ]
- then
- zreload
- else
- git status
- fi
- else
- echo "$LEO_PREF_PATH is diverged!"
- git status
- fi
- # cd back
- cd $cwd
- }
- echo "[UPDATE LEO'S PREFERENCES]"
- update_leos_preferences
- ###################################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement