Last active
September 8, 2016 14:50
-
-
Save informationsea/6823970 to your computer and use it in GitHub Desktop.
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 -*- | |
# If not running interactively, don't do anything | |
[ -z "$PS1" ] && return | |
# ==== system configuration ==== | |
if [ -f /etc/bashrc ]; then | |
. /etc/bashrc | |
fi | |
# ======== misc ========== | |
stty stop undef | |
# ========= History ============= | |
HISTTIMEFORMAT="%y/%m/%d %H:%M:%S : " | |
HISTIGNORE=history | |
HISTSIZE=100000 | |
# don't put duplicate lines in the history. See bash(1) for more options | |
# ... or force ignoredups and ignorespace | |
HISTCONTROL=ignoredups:ignorespace | |
# append to the history file, don't overwrite it | |
shopt -s histappend | |
# ========== Prompt ============ | |
if [ "$UID" = "0" ];then | |
PS1="\[\033[35m\]\u\[\033[0m\]@" | |
else | |
PS1="\[\033[36m\]\u\[\033[0m\]@" | |
fi | |
if [ "$SSH_CONNECTION" = "" ];then | |
PS1="$PS1\[\033[36m\]\h\[\033[0m\] \W\$ " | |
else | |
PS1="$PS1\[\033[35m\]\h\[\033[0m\] \W\$ " | |
fi | |
# ========== Completion (Bash only) ========= | |
if [ "$BASH_VERSION" ];then | |
for i in /opt/local/etc /usr/local/etc /etc; do | |
if [ -f $i/bash_completion ];then | |
. $i/bash_completion | |
fi | |
done | |
fi | |
# ========= Xterm Window Title ====== | |
case "${TERM}" in | |
kterm*|xterm*) | |
precmd() { | |
echo -ne "\e]0;${USER}@${HOST%%.*}:${PWD}\007" | |
} | |
;; | |
screen*) | |
preexec(){ | |
# http://d.hatena.ne.jp/aki03/20080216/1203146992 | |
local cmd | |
cmd=(${(z)2}) | |
echo -ne "\ek`basename ${cmd[1]}`:`basename ${PWD}`\e\\" | |
} | |
precmd() { | |
echo -ne "\eP\e]0;${USER}@${HOST%%.*}:${PWD}\007\e\\" | |
echo -ne "\ek`basename ${PWD}`\e\\" | |
} | |
;; | |
esac | |
# =========== 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 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 | |
} | |
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" | |
;; | |
darwin*) | |
# Java | |
#alias java="java -Dfile.encoding=UTF-8" | |
#alias javac="env LC_ALL=C javac -encoding UTF-8" | |
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" | |
# ls | |
alias la="ls -AG" | |
alias ll="ls -lGh" | |
alias lla="ls -lGhA" | |
alias l='ls -CFG' | |
alias ls="ls -G" | |
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 [ -e /opt/local/apache2/bin/apachectl ];then | |
alias mp-apachctrl="sudo /opt/local/apache2/bin/apachectl" | |
fi | |
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 | |
;; | |
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 | |
tmux set-option -g default-shell "$HOME/local/bin/zsh" | |
export TERM=xterm-256color | |
fi | |
fi | |
fi | |
if [ "$XAUTHORITY" = "" ];then | |
export XAUTHORITY=~/.Xauthority | |
fi | |
;; | |
esac | |
# ======== Additional paths ========== | |
if [ -d /opt/local/bin ];then | |
export PATH=/opt/local/bin:/opt/local/sbin:$PATH | |
export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig:$PKG_CONFIG_PATH | |
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 | |
fi | |
function add_path() { | |
NEWPREFIX=$1 | |
if [ -d ${NEWPREFIX}/bin ];then | |
export PATH=${NEWPREFIX}/bin:$PATH | |
export PKG_CONFIG_PATH=${NEWPREFIX}/lib/pkgconfig:$PKG_CONFIG_PATH | |
export LD_LIBRARY_PATH=${NEWPREFIX}/lib64:${NEWPREFIX}/lib:$LD_LIBRARY_PATH | |
export MANPATH=${NEWPREFIX}/share/man:$MANPATH | |
if [ -f ${NEWPREFIX}/bin/virtualenvwrapper_lazy.sh ];then | |
source ${NEWPREFIX}/bin/virtualenvwrapper_lazy.sh | |
fi | |
fi | |
} | |
add_path "$HOME/local" | |
if [ -d /usr/local/ncbi/blast/bin ];then | |
export PATH=/usr/local/ncbi/blast/bin:$PATH | |
export BLASTDB=/usr/local/ncbi/blast-db | |
fi | |
# ======= private ===== | |
if [ -f $HOME/.zsh.d/private.sh ];then | |
source $HOME/.zsh.d/private.sh | |
fi | |
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment