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