Skip to content

Instantly share code, notes, and snippets.

@mrleolink
Last active November 27, 2016 09:02
Show Gist options
  • Save mrleolink/84c5284c73c5a415ca871682004e4160 to your computer and use it in GitHub Desktop.
Save mrleolink/84c5284c73c5a415ca871682004e4160 to your computer and use it in GitHub Desktop.
My .zshrc
# General
export LANG=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# Path to your oh-my-zsh installation.
export ZSH=~/Dropbox/MY/Preferences/Unix/\[dot\]oh-my-zsh
export MANPATH="/usr/local/man:$MANPATH"
export SSH_KEY_PATH="~/.ssh/dsa_id"
# zsh custom folder
ZSH_CUSTOM="$ZSH/custom"
# Preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
export EDITOR='vim'
else
export EDITOR='nvim'
fi
# 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=(git adb colored-man zsh-syntax-highlighting) # SOURCE zsh-syntax-highlighting LAST!!!!
# 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 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 lol1='ping 216.52.241.254'
alias lol2='ping 104.160.131.1'
alias fuck='sudo'
alias db='cd ~/Dropbox'
alias dropbox='cd ~/Dropbox'
alias desktop='cd ~/Desktop'
# VIM
alias vi='nvim'
alias vim='nvim'
alias vimconf='vi ~/.config/nvim/init.vim'
# SUBLIME TEXT 2
alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"
# ZSHRC
alias zconf='vi ~/.zshrc'
alias zreload='source ~/.zshrc'
alias -s txt=vim
alias -s rb=subl
alias -s py=subl
alias -s xml=subl
alias -s json=subl
alias -s gradle=subl
alias -s md=subl
alias -s java=subl
# 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
# RUBY
alias wr='~/Dropbox/workspace-Ruby'
# ANDROID
alias adb_foreground_activity='adb shell dumpsys window windows | grep -E "mCurrentFocus|mFocusedApp"'
# 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
# less
alias less='less -R -s -M +Gg' # http://stackoverflow.com/questions/1049350/unable-to-make-less-to-indicate-location-in-percentage
# ag (The Silver Searcher)
alias ag='ag --pager "less -R"'
# git
alias gitconf='vi ~/.gitconfig'
alias ga='git add'
alias gaa='git add -A'
alias gs='git status'
alias gl='git lg'
alias gla='git lg --all'
alias gd='git diff'
alias gb='echo $'\n'; git checkout `git branch | peco | sed -e "s/\* //g" | awk "{print \$1}"`'
alias gba='echo $'\n'; git checkout `git branch -a | peco | sed -e "s/\* //g" | awk "{print \$1}"`'
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'
### Work's Mac
# PATHS
export STUDIO_VM_OPTIONS=~/Dropbox/MY/Preferences/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`
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`
# ALIASES
alias workspace='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 "No need to update!"
return 1
fi
fi
}
## UPDATE
function update_leos_config() {
# save current directory
local cwd=$(pwd)
# update oh-my-zsh
tput setaf 1; tput bold; echo "\n\n=====>> [UPDATING] oh-my-zsh...\n"; tput sgr0
upgrade_oh_my_zsh
# update zsh-syntax-highlighting
tput setaf 1; tput bold; echo "\n\n=====>> [UPDATING] zsh-syntax-highlighting...\n"; 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...\n"; 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...\n"; tput sgr0;
# update Pathogen itself
echo "\nUpdating $(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 pull
cd ..
done
# cd back to current directory
cd $cwd
## DONE
tput setaf 1; tput bold; echo "\n\nDONE!!!\nHave a nice day!\n\n"; tput sgr0;
}
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
# Redefine prompt_context for hiding user@hostname
prompt_context () { }
# Peco history
function peco-history-selection() {
unalias history
BUFFER=`history -n 1 | tail -r | awk '!a[$0]++' | peco`
CURSOR=$#BUFFER
zle reset-prompt
alias history='fc -il 1'
}
zle -N peco-history-selection
# Peco Git Checkout
function peco-git-checkout() {
gba
zle reset-prompt
}
zle -N peco-git-checkout
# Key Binding
bindkey '^R' peco-history-selection
bindkey '^B' peco-git-checkout
###################################################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment