Created
February 22, 2011 16:11
-
-
Save rainly/838883 to your computer and use it in GitHub Desktop.
This file contains 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
#This will load the current command into the editor defined in the variable VISUAL | |
# ctrl+x then ctrl+e | |
export VISUAL=vim | |
export EDITOR=vim | |
export VIM_APP_DIR="~/App/Bin" | |
export PATH="~/Local/bin:$PATH" | |
#Auto dir correction for cd | |
shopt -s cdspell | |
export CDPATH=".:$HOME:$HOME/Portfoliox" | |
export VERSIONER_PYTHON_PREFER_32_BIT=yes | |
export PYTHONPATH=$PYTHONPATH:~/Library/python | |
export DJANGO_COLORS="light" | |
export HISTCONTROL=erasedups | |
export HISTIGNORE="pwd:ls:cd:vim:e:vi:run:py:du:eva:svn:git" | |
export HISTTIMEFORMAT='%F %T ' | |
export HISTSIZE=500 | |
export MANPAGER='col -bx | vim -c ":set ft=man nonu nolist" -R -' | |
export GREP_OPTIONS="-n --color --exclude=\\*.svn\\*" | |
#Ignore certain files while tab completing | |
export FIGNORE=".svn:pyc:.o:~" | |
alias redo='sudo !!' | |
alias ms='mysql -uroot -p' | |
alias py='python2.6' | |
alias i='ipython' | |
alias pyc='find . -name "*.pyc" | xargs rm -rf' | |
alias run="python manage.py runserver 0.0.0.0:8000" | |
alias duck='du -sh' | |
alias cwd='pwd | pbcopy' | |
alias gowd='cd "`pbpaste`"' | |
alias e='vim' | |
if [ `uname` = 'Darwin' ]; then | |
alias vi='~/App/bin/MacVim.app/Contents/MacOS/Vim' | |
alias vim='~/App/bin/MacVim.app/Contents/MacOS/Vim' | |
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'" | |
alias grep="grep --color=auto" | |
alias e='mvim' | |
alias update='sudo port selfupdate; sudo port upgrade outdated' | |
fi | |
alias gfw="ssh -D 7777 -f -C -q -N [email protected]" | |
alias ..='cd ..;ls' | |
alias ...='cd ../..;ls' | |
alias ....='cd ../../../;ls' | |
alias dh='df -h' | |
alias rm='rm -i' | |
alias l='ls -CF' | |
alias ls='ls -G' | |
alias la='ls -A' | |
alias lh='ll -h' | |
alias ll='ls -l -G' | |
alias lla='ll -A' | |
alias dir='ls -ba' | |
alias lla="ls -Gla" # long list all, includes dot files | |
alias stfu="osascript -e 'set volume output muted true'" | |
alias pumpitup="sudo osascript -e 'set volume 10'" | |
# Get readable list of network IPs | |
alias ips="ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'" | |
alias myip="dig +short myip.opendns.com @resolver1.opendns.com" | |
alias flush="dscacheutil -flushcache" # Flush DNS cache | |
alias gzip="gzip -9n" # set strongest compression level as ‘default’ for gzip | |
alias ping="ping -c 5" # ping 5 times ‘by default’ | |
alias ql="qlmanage -p 2>/dev/null" # preview a file using QuickLook | |
alias show_hidden="defaults write com.apple.finder AppleShowAllFiles TRUE && killall Finder" | |
alias hide_hidden="defaults write com.apple.finder AppleShowAllFiles FALSE && killall Finder" | |
if [ `uname` = 'Linux' ]; then | |
alias ls='ls --color=auto' | |
fi | |
alias hex="od -tx1 -tc -Ax" | |
alias update='sudo apt-get update; sudo apt-get upgrade' | |
function getOS(){ | |
platform = 'unknown' | |
unamestr = `uname` | |
if [[ "$unamestr" == 'Linux' ]]; then | |
platform = 'linux' | |
elif [[ "$unamestr" == 'Darwin' ]]; then | |
platform = 'mac' | |
elif [[ "$unamestr" == 'FreeBSD' ]]; then | |
platform = 'freebsd' | |
fi | |
return platform | |
} | |
# calc 2*3, echo = 6 | |
# you can use "echo $((16/2))" also | |
function calc() { | |
awk "BEGIN{ print $* }"; | |
} | |
# cleaning files | |
function clean() { | |
if [ $# = "1" ] | |
then | |
find . -name "$1" | xargs rm -rf | |
else | |
echo "Usage: clean files, such as 'clean .svn, clean *.pyc, clean .DS_Store'" | |
fi | |
} | |
# md: mkdir, then cd | |
function md() { | |
if [ $# = "1" ] | |
then | |
mkdir -p "$1" | |
cd "$1" | |
else | |
echo "Usage: mkcd folder" | |
fi | |
# mkdir -p "$@" && eval cd "\"\$$#\""; | |
} | |
function psgrep() { | |
ps aux | grep "$1" | grep -v "grep" | |
} | |
function psterm() { | |
[ ${#} -eq 0 ] && echo "usage: $FUNCNAME STRING" && return 0 | |
local pid | |
pid=$(ps ax | grep "$1" | grep -v grep | awk '{ print $1 }') | |
echo -e "terminating ‘$1’ / process(es):\n$pid" | |
kill -SIGTERM $pid | |
} | |
function check_compression() { | |
curl -I -H 'Accept-Encoding: gzip,deflate' $1 | grep "Content-Encoding" | |
} | |
function cdl() { | |
cd "${1}"; | |
ls; | |
#cd $* && ls --color | |
} | |
function net() { | |
netstat -nat | awk '{print $6}' | sort | uniq -c | sort -rn | head -20 | |
} | |
#top command you ever used | |
function his() { | |
history | awk {'print $2'} | sort | uniq -c | sort -k1 -rn | head | |
} | |
#lets you do a quick search of your running processes | |
#for a case-insensitive partial match of the first parameter passed to it. | |
#find and list processes matching a case-insensitive partial-match string | |
function findProcess() { | |
ps Ao pid,comm | awk '{match($0,/[^\/]+$/); print substr($0,RSTART,RLENGTH)": "$1}' | grep -i $1 | grep -v grep | |
} | |
# build menu to kill process | |
function killProcess() { | |
IFS=$'\n' | |
PS3='Kill which process? ' | |
select OPT in $(fp $1) "Cancel"; do | |
if [ $OPT != "Cancel" ]; then | |
kill $(echo $OPT|awk '{print $NF}') | |
fi | |
break | |
done | |
unset IFS | |
} | |
#cd somewhere and type "m 1". | |
#Later on just typing "1" will return to that directory. | |
function m() { | |
alias $1=cd\ $PWD; | |
} | |
#Open a man page in Preview: | |
function pman() { | |
man -t $@ | open -f -a /Applications/Preview.app | |
} | |
# Quit an OS X application from the command line | |
function quit() { | |
for app in $*; do | |
osascript -e 'quit app "'$app'"' | |
done | |
} | |
#Relaunch an app from the command line: | |
function relaunch() { | |
for app in $*; do | |
osascript -e 'quit app "'$app'"'; | |
sleep 2; | |
open -a $app | |
done | |
} | |
function saver () { | |
/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background & | |
#killall ScreenSaverEngine | |
} | |
function color_test { | |
# Daniel Crisman's ANSI color chart script from | |
# The Bash Prompt HOWTO: 6.1. Colours | |
# http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html | |
# | |
# This function echoes a bunch of color codes to the | |
# terminal to demonstrate what's available. Each | |
# line is the color code of one forground color, | |
# out of 17 (default + 16 escapes), followed by a | |
# test use of that color on all nine background | |
# colors (default + 8 escapes). | |
T='Vim' # The test text | |
echo -e "\n def 40m 41m 42m 43m 44m 45m 46m 47m"; | |
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \ | |
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \ | |
' 36m' '1;36m' ' 37m' '1;37m'; | |
do FG=${FGs// /} | |
echo -en " $FGs \033[$FG $T " | |
for BG in 40m 41m 42m 43m 44m 45m 46m 47m; | |
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m"; | |
done | |
echo; | |
done | |
echo | |
} | |
# Upload image to Imgur and return its URL. Get API key at http://imgur.com/register/api_anon | |
function imgur() { | |
curl -F "image=@$1" -F "key=ANONYMOUS_IMGUR_API_KEY" https://api.imgur.com/2/upload | egrep -o "<original>.+?</original>" | egrep -o "http://imgur\.com/[^<]+" | sed "s/imgur.com/i.imgur.com/" | tee >(pbcopy); | |
} | |
#Automagically dump your public ssh key to a host for future passwordless auth: | |
function ssh-setup() { | |
cat ~/.ssh/id_rsa.pub | ssh $1 'cat - >> ~/.ssh/authorized_keys'; | |
} | |
port() { | |
netstat -tlnp|grep LISTEN|grep :$1 | |
if [ $? = 0 ]; then | |
log PASS $1端口已启动监听 | |
else | |
log ERROR $1端口未启动监听 | |
fi | |
} | |
fileExist() { | |
filename=$1 | |
if [ -e "${filename}" ] | |
then | |
log PASS $1 '文件存在' | |
else | |
log ERROR $1 '文件不存在' | |
fi | |
} | |
export PS1="\u@\h\w: " #init | |
if [ "$TERM" != 'dumb' ] && [ -n "$BASH" ] && [ -n "$PS1" ]; then | |
if [ `/usr/bin/whoami` = 'root' ] ; then | |
export PS1='\[\033[01;31m\]\h \[\033[01;34m\]\W \$ \[\033[00m\]' | |
else | |
#export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]' | |
export PS1='[\[\033[36m\]\u@\h\[\033[31m\]:\[\033[33m\]\w\[\033[0m\]]\[\033[35m\]\[\033[0m\]\$ ' | |
fi | |
fi | |
if [ -f /etc/bash_completion ]; then | |
. /etc/bash_completion | |
fi | |
if [ -f /opt/local/etc/bash_completion ]; then | |
source /opt/local/etc/bash_completion | |
fi | |
if [ -d ~/Dropbox/Data/etc/bash/completion ]; then | |
source ~/Dropbox/Data/etc/bash/completion/django | |
source ~/Dropbox/Data/etc/bash/completion/git | |
fi | |
if [ -f ~/Dropbox/Data/etc/bash/bin/z.sh ]; then | |
source ~/Dropbox/Data/etc/bash/bin/z.sh | |
fi | |
export LANGUAGE=en_US.UTF-8 | |
export LANG=en_US.UTF-8 | |
export LC_ALL=en_US.UTF-8 | |
# MacPorts Installer addition on 2010-03-06_at_00:25:32: adding an appropriate PATH variable for use with MacPorts. | |
export PATH=/opt/local/bin:/opt/local/sbin:$PATH | |
# Finished adapting your PATH environment variable for use with MacPorts. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment