Skip to content

Instantly share code, notes, and snippets.

@notsobad
Created March 9, 2012 05:51
Show Gist options
  • Save notsobad/2005229 to your computer and use it in GitHub Desktop.
Save notsobad/2005229 to your computer and use it in GitHub Desktop.
My bash profile, and shell utils
#!/bin/sh
# By notsobad
# variables
C_DEFAULT="\[\033[m\]"
C_WHITE="\[\033[1m\]"
C_BLACK="\[\033[30m\]"
C_RED="\[\033[31m\]"
C_GREEN="\[\033[32m\]"
C_YELLOW="\[\033[33m\]"
C_BLUE="\[\033[34m\]"
C_PURPLE="\[\033[35m\]"
C_CYAN="\[\033[36m\]"
C_LIGHTGRAY="\[\033[37m\]"
C_DARKGRAY="\[\033[1;30m\]"
C_LIGHTRED="\[\033[1;31m\]"
C_LIGHTGREEN="\[\033[1;32m\]"
C_LIGHTYELLOW="\[\033[1;33m\]"
C_LIGHTBLUE="\[\033[1;34m\]"
C_LIGHTPURPLE="\[\033[1;35m\]"
C_LIGHTCYAN="\[\033[1;36m\]"
C_BG_BLACK="\[\033[40m\]"
C_BG_RED="\[\033[41m\]"
C_BG_GREEN="\[\033[42m\]"
C_BG_YELLOW="\[\033[43m\]"
C_BG_BLUE="\[\033[44m\]"
C_BG_PURPLE="\[\033[45m\]"
C_BG_CYAN="\[\033[46m\]"
C_BG_LIGHTGRAY="\[\033[47m\]"
export PS1="$C_LIGHTGREEN\u$C_DARKGRAY@$C_BLUE\h $C_DARKGRAY: $C_LIGHTYELLOW\w$C_DARKGRAY\$$C_DEFAULT "
export PATH=$PATH:/usr/local/apache2/bin:/usr/local/mongodb/bin:/usr/local/node/bin
export SVN_EDITOR=vim
export CLICOLOR=1;
export LSCOLORS=exfxcxdxbxegedabagacad;
# alias
alias grepy='find . -name \*.py | xargs grep --color'
alias grephtml='find . -name \*.html | xargs grep --color'
alias la='ls -A'
alias ll='ls -l'
alias rd='rdesktop -uadministrator -pxxxxxx x.x.x.x'
alias t='tree'
alias fq='ssh vps -D 9999'
alias rd='rdesktop -uadministrator -p'xxxx' 192.168.10.205 '
alias h='php -r "echo htmlspecialchars( file_get_contents(\"php://stdin\") );"'
alias fd='firefox -P dev -no-remote'
alias all_bin="find `echo $PATH | tr ':' ' '` -maxdepth 1 -executable -mount -type f 2>/dev/null"
alias mysql='mysql --pager="less -n -i -S -F -X"'
alias f='nautilus .'
alias pdf=evince
# functions
#按日期后缀备份文件
bak(){ to="`echo $1 | sed 's#/*$##g'`.`date +%Y%m%d%H%M`"; [ -e "$to" ] && rm -rf $to; cp -rf "$1" $to; }
#随机看一幅漫画图片
xkcd(){ wget -q http://dynamic.xkcd.com/comic/random/ -O - | grep -Eo http://imgs.xkcd.com/comics/.*g | wget -q -i - -O - | display; }
#随机查看一个shell技巧
shellfu(){
curl -s "http://www.shell-fu.org/lister.php?random" | sed -e 's/<div/\n<div/g' -e 's/<\/div>/\n<\/div>\n/g' | sed -n -e "/<div class='tipbody'>/,/<\/div>/p" | lynx -stdin -dump -nolist;
}
#在当前目录开启一个简单的HTTP Server
serv(){ ip=`ifconfig eth0 | sed -n 's/^\s*inet [^:]*://p' | awk '{print $1}'`; echo http://$ip:8000; python -m SimpleHTTPServer; }
nc2mc='nc 127.0.0.1 11211'
mc_set(){ printf "set $1 0 ${3:-0} ${#2}\r\n$2\r\n" | $nc2mc; }
mc_get(){ printf "get $1\r\n" | $nc2mc; }
mc_delete(){ printf "delete $1\r\n" | $nc2mc; }
mc_status(){ printf "stats\r\n" | $nc2mc; }
mc_top(){ watch "printf 'stats\r\n' | $nc2mc"; }
set_mac(){ sudo ifconfig eth0 down; sudo ifconfig eth0 hw ether 00:24:e8:e6:b4:99; sudo ifconfig eth0 up; }
wifi(){ sudo ifconfig eth1 down; sudo ifconfig eth1 hw ether 00:22:08:e5:a4:19; sudo ifconfig eth1 up; nm-applet; }
set_net_job(){ sudo ifconfig eth0 10.2.4.8 netmask 255.255.0.0;sudo route add default gw 10.2.255.254; }
export_var(){
eval "export $(tr '\0' '\n' < /proc/$(pgrep -u $(whoami) -n nautilus)/environ | grep '^DBUS_SESSION_BUS_ADDRESS=')"
}
clock_girl(){ eval "export $(tr '\0' '\n' < /proc/$(pgrep -u $(whoami) -n nautilus)/environ | grep '^DBUS_SESSION_BUS_ADDRESS=')"; /usr/bin/gconftool-2 --set /desktop/gnome/background/picture_filename --type string /home/wang/file/clock_girl/`date +'%H%M'`.jpg; }
alert(){ gmessage -center -nofocus -font "Sans Bold 48" "$@" -fg green -borderless -wrap; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment