You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bashrc 14 KiB

13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. #!/bin/bash
  2. ##########################
  3. # system type
  4. alias ismsys=false
  5. alias iscygwin=false
  6. alias iswindows=false
  7. alias isdarwin=false
  8. alias islinux=false
  9. case `uname` in
  10. (MINGW*) alias ismsys=true ;;
  11. (CYGWIN*) alias iscygwin=true ;;
  12. (Darwin*) alias isdarwin=true ;;
  13. (Linux*) alias islinux=true ;;
  14. esac
  15. ( ismsys || iscygwin ) && alias iswindows=true
  16. ##########################################
  17. null(){
  18. "$@" >/dev/null 2>&1
  19. }
  20. __try_exec(){
  21. type $1 >/dev/null 2>&1 && "$@"
  22. }
  23. export PS1 # PS1 is defined later
  24. # PROMPT_COMMAND=prompt_function
  25. if false iswindows
  26. then
  27. export PAGER='tr -d \\r | less'
  28. else
  29. export PAGER="less"
  30. fi
  31. export LESS="-iRMXF"
  32. if null type vim
  33. then
  34. export EDITOR=vim
  35. else
  36. export EDITOR=vi
  37. fi
  38. export LC_MESSAGES=C
  39. # export CDPATH=".:~"
  40. export VISUAL="$EDITOR"
  41. export GIT_PAGER="$PAGER"
  42. export GIT_EDITOR="$EDITOR"
  43. test -z "$TMP" && export TMP=/tmp/${USER}-tmp
  44. mkdir -p "$TMP"
  45. ! iswindows && null type stty && {
  46. stty stop undef # unbind C-s to stop displaying output
  47. # stty erase '^h'
  48. }
  49. if iswindows; then
  50. # export PS1=" \[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ "
  51. # export PS1=" [\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ "
  52. export USER=$USERNAME
  53. fi
  54. #######################
  55. iswindows && alias tty="echo cmd.exe"
  56. type fortune >/dev/null 2>&1 && {
  57. echo
  58. fortune
  59. echo
  60. fortune -o
  61. echo
  62. }
  63. uname -a
  64. echo TERM $TERM $(tput colors) colors connected to $(tty), running $BASH $BASH_VERSION
  65. echo
  66. ###################################
  67. # some aliases and functions
  68. isdarwin || test "$TERM" == dumb || _coloroption=" --color=always"
  69. isdarwin || iswindows || _timeoption=" --time-style=long-iso"
  70. alias ls="ls -hCF${_coloroption}${_timeoption}"
  71. # export GREP_OPTIONS=""
  72. alias grep="grep -n${_coloroption}"
  73. iswindows && alias grep="grep -n"
  74. # alias ll="ls -l"
  75. # alias la="ls -A"
  76. # alias lla="ls -Al"
  77. # alias less=""
  78. alias em="emacs -nw"
  79. null type vim && alias vi=vim
  80. alias pstree="LANG=C pstree"
  81. alias cp="cp -v"
  82. alias mv="mv -v"
  83. alias psaux="ps auxww"
  84. alias q=exit
  85. alias e3=e3em
  86. alias dirs="dirs -v -l | \grep -v \$(printf '%s$' \$PWD)"
  87. alias po=popd
  88. alias pu=pushd
  89. alias sudo="sudo " # use aliases through sudo
  90. alias halt="sudo halt"
  91. alias reboot="sudo reboot"
  92. alias suspend="dbus-send --system --print-reply --dest=org.freedesktop.UPower \
  93. /org/freedesktop/UPower org.freedesktop.UPower.Suspend"
  94. alias hibernate="dbus-send --system --print-reply --dest=org.freedesktop.UPower \
  95. /org/freedesktop/UPower org.freedesktop.UPower.Hibernate"
  96. alias rand="echo \$RANDOM"
  97. alias xunp="file-roller -h"
  98. alias pc="sudo \paco -D"
  99. alias pycalc="python -i -c 'from math import *' "
  100. alias py3=python3
  101. alias py2=python2
  102. alias _reloadrc="test -f ~/.bashrc && source ~/.bashrc"
  103. # alias mytime="date +%Y%m%d-%H%M%S"
  104. alias sh="ENV=$HOME/.shrc PS1=\$\ PROMPT_COMMAND="" sh"
  105. # type trash >/dev/null 2>&1 && alias rm=trash
  106. alias mpg123="mpg123 -C -v --title"
  107. export PLAYER="mpg123 -C -v --title"
  108. alias screen="screen -e^z^z"
  109. alias zcd="cd \`zenity --file-selection --directory\`"
  110. alias pad=notepad
  111. null type gedit && alias pad=gedit
  112. null type leafpad && alias pad=leafpad
  113. alias wic=wicd-curses
  114. alias wil="wicd-cli -y -l | head"
  115. #alias wicn="wicd-cli -y -c -n"
  116. wicn(){
  117. if test $# -eq 0
  118. then
  119. local num
  120. wicd-cli -y -l | head
  121. echo -n "input num: "
  122. read num
  123. test -n "$num" && wicd-cli -y -c -n $num
  124. else
  125. wicd-cli -y -c -n $1
  126. fi
  127. }
  128. alias aptin="apt-get install"
  129. alias aptsearch="apt-cache search"
  130. alias aptshow="apt-cache show"
  131. for f in /usr/share/vim/vimcurrent/macros/less.sh \
  132. /usr/share/vim/vim73/macros/less.sh
  133. do
  134. test -f $f && alias vl=$f && break
  135. done
  136. alias yt=yaourt
  137. null type pacman-color && {
  138. alias pacman=pacman-color
  139. export pacman_program=pacman-color # used by pacmatic
  140. export PACMAN=pacman-color # used by yaourt
  141. }
  142. null type pacmatic && {
  143. alias pacman="pacmatic"
  144. export PACMAN="pacmatic"
  145. }
  146. alias ubuntu-upgrade="sudo apt-get autoremove --yes && sudo apt-get update --yes && sudo apt-get upgrade --yes"
  147. alias arch-upgrade="sudo pacman -Syu"
  148. alias port-upgrade="port selfupdate && port sync && port upgrade installed"
  149. if iscygwin; then
  150. null type windate || alias windate="/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%'"
  151. alias cygsu="cygstart /cygwinsetup.exe"
  152. alias emacs="CYGWIN=tty emacs -nw"
  153. alias ls="ls -CFG $(iswindows || test "$TERM" == dumb || echo --color=auto)"
  154. fi
  155. alias g=git
  156. if null type _git # enable programmable completion for g
  157. then
  158. complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
  159. || complete -o default -o nospace -F _git g
  160. fi
  161. tmux_main(){
  162. if tmux has -t main
  163. then
  164. if tmux lsc -t main
  165. tmux new
  166. else
  167. tmux attach -t main
  168. fi
  169. else
  170. tmux new -s main
  171. fi
  172. }
  173. __my_moc_state(){
  174. type mocp >/dev/null 2>&1 || return
  175. test "`mocp -Q %state 2>/dev/null`" == PLAY || return
  176. printf "$1" "`mocp -Q %title 2>/dev/null`"
  177. }
  178. mcrypt-stream(){
  179. test $# -eq 2 || return 1
  180. case $1 in
  181. en)
  182. mcrypt --key $2 | base64 ;;
  183. de)
  184. base64 -d | mcrypt -d --key $2 ;;
  185. esac
  186. }
  187. gpg-stream(){
  188. test $# -eq 2 || return 1
  189. case $1 in
  190. en)
  191. gpg --passphrase $2 -c --batch |base64 ;;
  192. de)
  193. base64 -d|gpg --passphrase $2 -d --batch ;;
  194. esac
  195. }
  196. alias enst="gpg-stream en"
  197. alias dest="gpg-stream de"
  198. showinfo(){
  199. echo "Japanese letters are 表示可能"
  200. __try_exec diskinfo
  201. ! isdarwin && test -n "${DISPLAY}" && {
  202. __try_exec xrandr | \grep --color=never ^Screen
  203. }
  204. iswindows || __try_exec finger $USER
  205. LANG=C __try_exec id
  206. __try_exec xset q
  207. }
  208. x(){
  209. if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  210. #mkdir -p ~/.my/log
  211. # nohup startx >~/.my/log/xorg.log 2>&1 &
  212. # exit
  213. exec startx
  214. else
  215. echo "X cant be started! Maybe another X is already running or something." 1>&2
  216. fi
  217. }
  218. bak(){
  219. for file in "$@"
  220. do
  221. cp -v ${file} ${file}.bak
  222. done
  223. }
  224. di(){
  225. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  226. then
  227. local diffcmd=colordiff
  228. else
  229. local diffcmd=diff
  230. fi
  231. ${diffcmd} -u "$@" | ${PAGER}
  232. }
  233. tb(){
  234. local tb=~/.my/tb
  235. mkdir -p $tb
  236. for file in "$@"
  237. do
  238. mv $file $tb
  239. done
  240. }
  241. mkcd(){
  242. mkdir -p $1
  243. cd $1
  244. }
  245. catclip(){
  246. if iswindows
  247. then
  248. cat /dev/clipboard | tr -d \\r
  249. else
  250. xclip -o -selection "clipboard"
  251. fi
  252. }
  253. setclip(){
  254. if iswindows
  255. then
  256. if test $# -eq 0
  257. then
  258. sed -e 's/$/\r/' | tee /dev/clipboard
  259. else
  260. cat "$@" | sed -e 's/$/\r/' | tee /dev/clipboard
  261. fi
  262. else
  263. if test $# -eq 0
  264. then
  265. xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  266. else
  267. cat "$@" | xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  268. fi
  269. fi
  270. }
  271. if iswindows; then
  272. alias _open_file='cmd.exe //c start ""'
  273. elif isdarwin; then
  274. alias _open_file=open
  275. elif islinux; then
  276. if null type pcmanfm; then
  277. alias _open_file="LC_MESSAGES= pcmanfm"
  278. else
  279. alias _open_file="LC_MESSAGES= xdg-open"
  280. fi
  281. else
  282. alias _open_file=cat
  283. fi
  284. o(){
  285. if test $# -eq 0
  286. then
  287. _open_file . >/dev/null 2>&1 &
  288. else
  289. for f in "$@"
  290. do
  291. if test -d $f
  292. then
  293. _open_file $f >/dev/null 2>&1 &
  294. else
  295. _open_file $f >/dev/null 2>&1 &
  296. fi
  297. done
  298. fi
  299. }
  300. convmv-sjis2utf8-test(){
  301. convmv -r -f sjis -t utf8 *
  302. }
  303. convmv-sjis2utf8-notest(){
  304. convmv -r -f sjis -t utf8 * --notest
  305. }
  306. __my_parse_svn_branch() {
  307. local LANG=C
  308. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  309. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  310. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  311. }
  312. __my_svn_ps1(){
  313. if svn status >/dev/null 2>&1
  314. then
  315. local svn_branch=$(__my_parse_svn_branch)
  316. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  317. fi
  318. }
  319. #Change ANSI Colors
  320. _chengecolors(){
  321. echo -e \
  322. "\e]P0000000" \
  323. "\e]P1cd0000" \
  324. "\e]P200cd00" \
  325. "\e]P3cdcd00" \
  326. "\e]P41e90ff" \
  327. "\e]P5cd00cd" \
  328. "\e]P600cdcd" \
  329. "\e]P7353535" \
  330. "\e]P8666666" \
  331. "\e]P9ff9999" \
  332. "\e]Pa99ff99" \
  333. "\e]Pbffff99" \
  334. "\e]Pc9999ff" \
  335. "\e]Pdff99ff" \
  336. "\e]Pe99ffff" \
  337. "\e]Pfffffff"
  338. }
  339. # printf "\e]P7353535" \
  340. _colors(){
  341. echo -e \
  342. "\e[30mBlack" \
  343. "\e[31mRed" \
  344. "\e[32mGreen" \
  345. "\e[33mYellow" \
  346. "\e[34mBlue" \
  347. "\e[35mMagenta" \
  348. "\e[36mCyan" \
  349. "\e[37mWhite"
  350. echo -e \
  351. "\e[30;1mBright Black" \
  352. "\e[31;1mBright Red" \
  353. "\e[32;1mBright Green" \
  354. "\e[33;1mBright Yellow" \
  355. "\e[34;1mBright Blue" \
  356. "\e[35;1mBright Magenta" \
  357. "\e[36;1mBright Cyan" \
  358. "\e[37;1mBright White\n" \
  359. "\e[0m"
  360. }
  361. winln(){
  362. # for windose make link (actually junction)
  363. if test $# -eq 0
  364. then
  365. {
  366. echo "usage: winln TARGET LINK_NAME"
  367. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  368. echo "About other features run 'junction'."
  369. } 1>&2
  370. return 1
  371. else
  372. junction "$2" "$1"
  373. fi
  374. }
  375. __my_battery_status(){
  376. local dir=/sys/class/power_supply/BAT0
  377. if test -d $dir
  378. then
  379. local st=$(cat $dir/status)
  380. local full=$(cat $dir/charge_full)
  381. local now=$(cat $dir/charge_now)
  382. local rate=$(expr $now \* 100 / $full)
  383. printf "$1" "${st}:${rate}%"
  384. fi
  385. }
  386. alias bat='__my_battery_status %s\\n'
  387. ip-address(){
  388. test type ifconfig >/dev/null 2>&1 || return 1
  389. local ip=$(LANG=C ifconfig | \grep --color=never "inet " | \grep --color=never -v "127.0.0.1" | awk '{print $2}')
  390. test -n "$ip" && printf $1 $ip
  391. }
  392. __my_ps1_moc(){
  393. local last=$?
  394. __my_moc_state "[MOC:%s]"
  395. return $last
  396. }
  397. __my_ps1_git(){
  398. local last=$?
  399. __try_exec __git_ps1 "[GIT:$(__try_exec git config --get user.name):%s]"
  400. return $last
  401. }
  402. __my_ps1_ipaddr(){
  403. local last=$?
  404. test -z "$DISPLAY" && ! iswindows && ip-address [Addr:%s]
  405. return $last
  406. }
  407. __my_ps1_bttry(){
  408. local last=$?
  409. local bst="${TMP}/batterystatus"
  410. if test -z "$DISPLAY" && ! iswindows
  411. then
  412. test -f $bst && local bstr="$(cat $bst)"
  413. test -n "$bstr" && echo "[Battery:$bstr]"
  414. __my_battery_status %s >$bst &
  415. fi
  416. return $last
  417. }
  418. __my_ps1_dirs(){
  419. dirs | wc -l
  420. }
  421. __my_ps1_jobs(){
  422. jobs | wc -l
  423. }
  424. if test "$TERM" != dumb
  425. then
  426. __my_c1="\[\e[1;31m\]" # color for PWD
  427. __my_c2="\[\e[0;36m\]" # color for user
  428. __my_c3="\[\e[1;30m\]" # color for OLDPWD
  429. __my_c4="\[\e[1;32m\]" # color for ::
  430. __my_cdef="\[\e[0m\]"
  431. fi
  432. _PS1="\
  433. ${__my_c4}:: ${__my_cdef}[${__my_c1}\w/${__my_cdef}<${__my_c3}\${OLDPWD}${__my_cdef}]\$(__my_ps1_git)\$(__my_ps1_bttry)\$(__my_ps1_ipaddr)\$(__my_ps1_moc)\n\
  434. ${__my_c4}:: ${__my_c2}\u@\H${__my_cdef} \D{%a, %d %b %Y %T %z} ${SHELL} \V\n\
  435. ${__my_c4}:: ${__my_cdef}shlv:${SHLVL} cnum:\# jobs:\j last:\$? \$ "
  436. PS1=$_PS1
  437. __my_set_title(){
  438. title="$(echo $@)"
  439. case $TERM in
  440. (rxvt*|xterm*|aterm|screen*)
  441. test -t 1 &&
  442. test -n "$DISPLAY" &&
  443. test -z "$EMACS" &&
  444. echo -n -e "\033]0;${title}\007"
  445. ;;
  446. esac
  447. }
  448. export PROMPT_COMMAND="__my_set_title \${USER}@\${HOSTNAME}\ \${PWD};"
  449. # copied from https://wiki.archlinux.org/index.php/X_resources
  450. invader(){
  451. # ANSI color scheme script featuring Space Invaders
  452. #
  453. # Original: http://crunchbanglinux.org/forums/post/126921/#p126921
  454. # Modified by lolilolicon
  455. #
  456. f=3 b=4
  457. for j in f b; do
  458. for i in {0..7}; do
  459. printf -v $j$i %b "\e[${!j}${i}m"
  460. done
  461. done
  462. bld=$'\e[1m'
  463. rst=$'\e[0m'
  464. cat << EOF
  465. $f1 ▀▄ ▄▀ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4 ▀▄ ▄▀ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  466. $f1 ▄█▀███▀█▄ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4 ▄█▀███▀█▄ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  467. $f1█▀███████▀█ $f2▀▀███▀▀███▀▀ $f3▀█▀██▀█▀ $f4█▀███████▀█ $f5▀▀███▀▀███▀▀ $f6▀█▀██▀█▀$rst
  468. $f1▀ ▀▄▄ ▄▄▀ ▀ $f2 ▀█▄ ▀▀ ▄█▀ $f3▀▄ ▄▀ $f4▀ ▀▄▄ ▄▄▀ ▀ $f5 ▀█▄ ▀▀ ▄█▀ $f6▀▄ ▄▀$rst
  469. $bld$f1▄ ▀▄ ▄▀ ▄ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4▄ ▀▄ ▄▀ ▄ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  470. $bld$f1█▄█▀███▀█▄█ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4█▄█▀███▀█▄█ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  471. $bld$f1▀█████████▀ $f2▀▀▀██▀▀██▀▀▀ $f3▀▀█▀▀█▀▀ $f4▀█████████▀ $f5▀▀▀██▀▀██▀▀▀ $f6▀▀█▀▀█▀▀$rst
  472. $bld$f1 ▄▀ ▀▄ $f2▄▄▀▀ ▀▀ ▀▀▄▄ $f3▄▀▄▀▀▄▀▄ $f4 ▄▀ ▀▄ $f5▄▄▀▀ ▀▀ ▀▀▄▄ $f6▄▀▄▀▀▄▀▄$rst
  473. $f7▌$rst
  474. $f7▌$rst
  475. $f7 ▄█▄ $rst
  476. $f7▄█████████▄$rst
  477. $f7▀▀▀▀▀▀▀▀▀▀▀$rst
  478. EOF
  479. }
  480. #/etc/lsb-release