Last active
September 8, 2016 14:49
-
-
Save informationsea/5401321 to your computer and use it in GitHub Desktop.
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
# -*- shell-script -*- | |
# private paths | |
if [ -f $HOME/.zsh.d/private-path.sh ];then | |
source $HOME/.zsh.d/private-path.sh | |
fi | |
# load system configuration | |
if [ -f "/etc/profile" ];then | |
source /etc/profile | |
fi | |
# ========== for ubuntu ========== | |
if [ -f "/etc/zsh_command_not_found" ];then | |
source /etc/zsh_command_not_found | |
fi | |
if [ -f "/etc/bash_completion.d/virtualenvwrapper" ];then | |
source /etc/bash_completion.d/virtualenvwrapper | |
fi | |
# ========= For Emacs Prompt ===== | |
if [ "$EMACS" ];then | |
export TERM=Eterm-color | |
fi | |
# ========= Prompt ======== | |
if [ "$SSH_CONNECTION$REMOTEHOST" = "" ];then | |
PS1="%(!.%F{magenta}.%F{cyan})%n%f@%F{cyan}%m%f %.%(!.#.$) " | |
else | |
PS1="%(!.%F{magenta}.%F{cyan})%n%f@%F{magenta}%m%f %.%(!.#.$) " | |
fi | |
RPROMPT="%F{cyan}%D %T%f %F{green}%~%f %(?..%F{red}%B%?%b%f)" | |
# for long time command | |
REPORTTIME=3 | |
# ========= History ============ | |
HISTFILE=$HOME/.zsh_history | |
HISTSIZE=100000 | |
SAVEHIST=500000 | |
setopt hist_ignore_dups # ignore duplication command history list | |
setopt share_history # share command history data | |
setopt extended_history | |
bindkey -e | |
autoload history-search-end | |
zle -N history-beginning-search-backward-end history-search-end | |
zle -N history-beginning-search-forward-end history-search-end | |
bindkey "^P" history-beginning-search-backward-end | |
bindkey "^N" history-beginning-search-forward-end | |
# ========== Completion =========== | |
zstyle :compinstall filename '$HOME/.zshrc' | |
autoload -Uz compinit | |
compinit | |
# http://journal.mycom.co.jp/column/zsh/009/index.html | |
zstyle ':completion:*' list-colors '' # color completion | |
zstyle ':completion:*' format '%BCompleting %d%b' | |
zstyle ':completion:*' group-name '' | |
zstyle ':completion:*:default' menu select=1 | |
setopt nolistbeep # do not beep on completion | |
setopt extendedglob | |
#autoload predict-on # prediction completion | |
#predict-on | |
# ========= Covinient Functions ====== | |
setopt auto_cd # auto pushd | |
setopt correct # correct your mis-spelled command | |
setopt list_packed # pack 'ls' | |
setopt no_flow_control # disable flow control | |
setopt noautoremoveslash # disable auto remove directory's slash | |
autoload zed | |
# http://www.clear-code.com/blog/2011/9/5.html | |
WORDCHARS=${WORDCHARS:s,/,,} # "/" is not word char | |
# ========= Xterm Window Title ====== | |
case "${TERM}" in | |
kterm*|xterm*) | |
precmd() { | |
echo -ne "\e]0;${USER}@${HOST%%.*}:${PWD}\007" | |
} | |
;; | |
esac | |
# ======== Additional paths ========== | |
function add_path() { | |
if [ ! -d $1 ];then | |
return | |
fi | |
NEWPREFIX=$1 | |
if [ -d ${NEWPREFIX}/bin ];then | |
export PATH=${NEWPREFIX}/bin:$PATH | |
fi | |
if [ "$LD_LIBRARY_PATH" ];then | |
export LD_LIBRARY_PATH=${NEWPREFIX}/lib64:${NEWPREFIX}/lib:$LD_LIBRARY_PATH | |
else | |
export LD_LIBRARY_PATH=${NEWPREFIX}/lib64:${NEWPREFIX}/lib | |
fi | |
if [ "$PKG_CONFIG_PATH" ];then | |
export PKG_CONFIG_PATH=${NEWPREFIX}/lib/pkgconfig:$PKG_CONFIG_PATH | |
else | |
export PKG_CONFIG_PATH=${NEWPREFIX}/lib/pkgconfig | |
fi | |
if [ "$MANPATH" ];then | |
export MANPATH=${NEWPREFIX}/share/man:$MANPATH | |
else | |
export MANPATH=${NEWPREFIX}/share/man:/usr/share/man:/user/local/share/man:/usr/X11/man | |
fi | |
if [ -f ${NEWPREFIX}/bin/virtualenvwrapper_lazy.sh ];then | |
source ${NEWPREFIX}/bin/virtualenvwrapper_lazy.sh | |
fi | |
} | |
add_path "$HOME/local" | |
# =========== misc functions ================== | |
function cleanpath() { | |
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin | |
unset PKG_CONFIG_PATH | |
unset DYLD_FALLBACK_LIBRARY_PATH | |
unset DYLD_LIBRARY_PATH | |
unset DYLD_FRAMEWORK_PATH | |
unset LD_LIBRARY_PATH | |
} | |
function countlines() { | |
local basedir=$1 | |
local currentlines='0' | |
local thislines | |
shift 1 | |
while [ $1 ] ;do | |
thislines=`find "$basedir" -type f -name "*.$1" -print0 | xargs -0 cat | wc -l` | |
currentlines=$(($thislines + $currentlines)) | |
shift 1 | |
done | |
echo $currentlines | |
} | |
function screenshot() { # for screenshot prompt | |
export PS1='%.%(!.#.$) ' | |
RPROMPT="" | |
precmd() { | |
echo -ne "\e]0;`basename ${PWD}`\007" | |
} | |
} | |
function highlighless() | |
{ | |
if type pygmentize-2.7 > /dev/null 2>&1; then | |
pygmentize-2.7 -P encoding=utf-8 $1|less -R | |
else | |
pygmentize -P encoding=utf-8 $1|less -R | |
fi | |
} | |
function t() | |
{ | |
if ! tmux a; then | |
tmux | |
fi | |
} | |
# ========== Environment variable & Alias ====== | |
export LESS='-R -P %f\ %Pb\%\ %lb/%L\ ?e(END)' | |
alias grep='grep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias egrep='egrep --color=auto' | |
alias nkf='nkf -w' | |
export PYTHONIOENCODING=utf-8 | |
# ========== Editor ============ | |
# Editor | |
MAC_EMACS=/Applications/Emacs.app/Contents/MacOS/Emacs | |
if [ -f $MAC_EMACS ];then | |
# export EDITOR="$MAC_EMACS -nw" | |
alias emacs="$MAC_EMACS -nw" | |
alias emacsclient="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient" | |
else | |
# export EDITOR=emacs | |
alias emacs="emacs -nw" | |
fi | |
# emacs | |
function e() { | |
emacsclient -t -c "$@" | |
if [ "$?" -eq 1 ];then | |
emacs --daemon | |
emacsclient -t -c "$@" | |
fi | |
} | |
alias quit-emacs='emacsclient -e "(kill-emacs)"' | |
## if vim is not found, use vi. http://www.clear-code.com/blog/2011/9/5.html | |
if ! type vim > /dev/null 2>&1; then | |
export EDITOR="vi" | |
alias vim=vi | |
else | |
export EDITOR="vim" | |
fi | |
# ========== Pager ========== | |
## http://www.clear-code.com/blog/2011/9/5.html | |
#if type lv > /dev/null 2>&1; then | |
# export PAGER="lv" | |
#else | |
export PAGER="less" | |
#fi | |
## -c: enable ANSI escape sequence color | |
export LV="-c" | |
# ========== Platform dependent ================ | |
case $OSTYPE in | |
freebsd*) | |
alias la="ls -AG" | |
alias ll="ls -lGh" | |
alias lla="ls -lGhA" | |
alias l='ls -CFG' | |
alias ls="ls -G" | |
export LSCOLORS="gxfxcxdxbxegedabagacad" | |
;; | |
darwin*) | |
# Java | |
#alias java="java -Dfile.encoding=UTF-8" | |
#alias javac="env LC_ALL=C javac -encoding UTF-8" | |
export JAVA6_HOME="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home" | |
export JAVA7_HOME="`find -s /Library/Java/JavaVirtualMachines -depth 1 -name 'jdk1.7*'|tail -n1`/Contents/Home" | |
export JAVA8_HOME="`find -s /Library/Java/JavaVirtualMachines -depth 1 -name 'jdk1.8*'|tail -n1`/Contents/Home" | |
alias usejdk6="export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home" | |
alias usejdk7="export JAVA_HOME=`find -s /Library/Java/JavaVirtualMachines -depth 1 -name 'jdk1.7*'|tail -n1`/Contents/Home" | |
alias usejdk8="export JAVA_HOME=`find -s /Library/Java/JavaVirtualMachines -depth 1 -name 'jdk1.8*'|tail -n1`/Contents/Home" | |
alias usejre="export JAVA_HOME=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home" | |
#export JAVA_HOME="/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home" | |
# ls | |
alias la="ls -AG" | |
alias ll="ls -lGh" | |
alias lla="ls -lGhA" | |
alias l='ls -CFG' | |
alias ls="ls -G" | |
export LSCOLORS="gxfxcxdxbxegedabagacad" | |
alias enablescreensharing="sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist" | |
alias disablescreensharing="sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.screensharing.plist" | |
alias ss="open /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app" | |
if [ "$TMUX" ]; then | |
tmux set-option -g status-right "#[bg=blue,bold] #(sysctl vm.loadavg | cut -d ' ' -f 3-5) #[bg=red] $USER@#H #[bg=blue,bold,fg=white] %Y/%m/%d (%a) %H:%M" > /dev/null 2> /dev/null | |
fi | |
add_path /opt/local | |
if [ -f /opt/local/bin/virtualenvwrapper.sh-2.7 ];then | |
if [ -f /opt/local/bin/virtualenvwrapper.sh ];then | |
source /opt/local/bin/virtualenvwrapper_lazy.sh-2.7 | |
else | |
source /opt/local/bin/virtualenvwrapper.sh-2.7 | |
fi | |
fi | |
if [ -d /Library/TeX/texbin ];then | |
export PATH=/Library/TeX/texbin:$PATH | |
fi | |
;; | |
linux* | cygwin) | |
alias la="ls -A --color=auto" | |
alias ll="ls -lhF --color=auto" | |
alias lla="ls -lhA --color=auto" | |
alias l='ls -CF --color=auto' | |
alias ls="ls --color=auto" | |
alias fls="=ls --color=never" | |
alias ffls="=ls --color=never -f" | |
unset SSH_ASKPASS | |
umask 022 | |
if [ -f /etc/redhat-release ]; then | |
if [ "`cat /etc/redhat-release|cut -f 1 -d .`" = "CentOS release 5" ]; then | |
echo "Cent OS 5" | |
if [ "$TMUX" ];then | |
if [ -f "$HOME/local/bin/zsh" ];then | |
tmux set-option -g default-shell "$HOME/local/bin/zsh" | |
fi | |
export TERM=xterm-256color | |
fi | |
fi | |
fi | |
if [ "$XAUTHORITY" = "" ];then | |
export XAUTHORITY=~/.Xauthority | |
fi | |
;; | |
esac | |
# ======= private ===== | |
if [ -f $HOME/.zsh.d/private.sh ];then | |
source $HOME/.zsh.d/private.sh | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment