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 20 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
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
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
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
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
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
13 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
12 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. #!/bin/bash
  2. # If not running interactively, don't do anything
  3. [[ $- != *i* ]] && return
  4. ##########################################
  5. null(){
  6. "$@" >/dev/null 2>&1
  7. }
  8. __try_exec(){
  9. type $1 >/dev/null 2>&1 && "$@"
  10. }
  11. ##########################
  12. # system type
  13. alias ismsys=false
  14. alias iscygwin=false
  15. alias iswindows=false
  16. alias isdarwin=false
  17. alias islinux=false
  18. alias with_coreutils=false # for mac
  19. case `uname` in
  20. (MINGW*) alias ismsys=true ;;
  21. (CYGWIN*) alias iscygwin=true ;;
  22. (Darwin*) alias isdarwin=true ;;
  23. (Linux*) alias islinux=true ;;
  24. esac
  25. null ls --version && alias with_coreutils=true
  26. ( ismsys || iscygwin ) && alias iswindows=true
  27. #################################
  28. if echo $PATH | grep "$HOME" >/dev/null 2&>1
  29. then
  30. PATH="${PATH}:${HOME}/.local/bin"
  31. fi
  32. if false iswindows
  33. then
  34. export PAGER='tr -d \\r | less'
  35. else
  36. export PAGER="less"
  37. fi
  38. export LESS="-iRMX"
  39. if null type vim
  40. then
  41. export EDITOR=vim
  42. else
  43. export EDITOR=vi
  44. fi
  45. export LANG=ja_JP.UTF-8
  46. export LC_MESSAGES=C
  47. # export CDPATH=".:~"
  48. export VISUAL="$EDITOR"
  49. export GIT_PAGER="less -F"
  50. export GIT_EDITOR="$EDITOR"
  51. if test -n "$TMUX" && \
  52. echo $TERM | grep screen >/dev/null 2>&1 && \
  53. tmux display -p '#{client_termname}' | grep 256color >/dev/null 2>&1
  54. then
  55. TERM=screen-256color
  56. fi
  57. test -z "$TMP" && export TMP=/tmp/${USER}-tmp
  58. mkdir -p "$TMP"
  59. ! iswindows && null type stty && {
  60. stty stop undef # unbind C-s to stop displaying output
  61. # stty erase '^h'
  62. }
  63. if iswindows; then
  64. # export PS1=" \[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ "
  65. # export PS1=" [\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ "
  66. export USER=$USERNAME
  67. fi
  68. _tmux_prefs(){
  69. null type tmux || return 1
  70. tmux set -g mode-keys vi
  71. }
  72. if test -d ~/dbx
  73. then
  74. export CHIT_PATH="$HOME/dbx/.chit"
  75. fi
  76. #######################
  77. iswindows && alias tty="echo cmd.exe"
  78. type fortune >/dev/null 2>&1 && {
  79. fortune
  80. echo
  81. fortune -o
  82. echo
  83. }
  84. uname -a
  85. echo TERM $TERM $(tput colors) colors connected to $(tty), \
  86. running $BASH $BASH_VERSION
  87. if test -n "$TMUX"
  88. then
  89. tmux display -p 'Using tmux #S:#I:#W.#P, client is #{client_termname}' \
  90. 2>/dev/null
  91. echo
  92. fi
  93. ###################################
  94. # some aliases and functions
  95. ( ! with_coreutils && isdarwin ) || test "$TERM" == dumb || \
  96. _coloroption=" --color=auto"
  97. ( ! with_coreutils && isdarwin ) || iswindows || \
  98. _timeoption=" --time-style=long-iso"
  99. ( ! with_coreutils && isdarwin ) || _hideoption=" --hide=[A-Z]*" # do not use
  100. _timeformat_iso="%Y-%m-%dT%H:%M:%S%z"
  101. _timeformat_rfc2822="%a, %d %b %Y %T %z"
  102. alias ls="ls -hCF${_coloroption}${_timeoption}"
  103. # export GREP_OPTIONS=""
  104. alias gr="grep -n --color=always"
  105. iswindows && alias grep="grep -n"
  106. # alias ll="ls -l"
  107. # alias la="ls -A"
  108. # alias lla="ls -Al"
  109. alias less="less -F"
  110. null type emacs && alias em="emacs -nw"
  111. null type vim && alias vi=vim
  112. alias pstree="LANG=C pstree"
  113. alias cp="cp -v"
  114. alias mv="mv -v"
  115. alias rm="rm -v"
  116. alias psaux="ps auxww"
  117. alias q=exit
  118. null type e3em && alias e3=e3em
  119. #alias dirs="dirs -v -l | \grep -v \$(printf '%s$' \$PWD)"
  120. alias po=popd
  121. alias pu=pushd
  122. alias sudo="sudo " # use aliases through sudo
  123. alias sudoe="sudoedit"
  124. alias halt="sudo halt"
  125. alias reboot="sudo reboot"
  126. null type dbus-send && {
  127. alias suspend="dbus-send --system --print-reply --dest=org.freedesktop.UPower \
  128. /org/freedesktop/UPower org.freedesktop.UPower.Suspend"
  129. alias hibernate="dbus-send --system --print-reply --dest=org.freedesktop.UPower \
  130. /org/freedesktop/UPower org.freedesktop.UPower.Hibernate"
  131. }
  132. alias rand="echo \$RANDOM"
  133. null type file-roller && alias xunp="file-roller -h"
  134. null type paco && alias pc="sudo \paco -D"
  135. alias pycalc="python -i -c 'from math import *' "
  136. null type python3 && alias py3=python3
  137. null type python2 && alias py2=python2
  138. alias _reloadrc="test -f ~/.bashrc && source ~/.bashrc"
  139. # alias mytime="date +%Y%m%d-%H%M%S"
  140. alias sh="ENV=$HOME/.shrc PS1=\$\ PROMPT_COMMAND="" sh"
  141. # type trash >/dev/null 2>&1 && alias rm=trash
  142. null type mpg123 && alias mpg123="mpg123 -C -v --title"
  143. null type xmms2 && alias xm="xmms2"
  144. #export PLAYER="mpg123 -C -v --title"
  145. null type screen && alias screen="screen -e^z^z"
  146. #alias zcd="cd \`zenity --file-selection --directory\`"
  147. null type gtags && alias gtags="gtags --verbose"
  148. null type htags && alias htags="htags --xhtml --symbol --line-number \
  149. --frame --alphabet --verbose"
  150. null type aunpack && alias aunp=aunpack
  151. null type lv && alias lv="lv|less"
  152. isdarwin && alias updatedb="LC_ALL=C updatedb"
  153. # do not use locate installed by macports
  154. isdarwin && test -x /usr/bin/locate && alias locate="/usr/bin/locate"
  155. # pad
  156. alias pad=notepad
  157. null type gedit && alias pad=gedit
  158. null type leafpad && alias pad=leafpad
  159. isdarwin && alias pad="open -e"
  160. null type wicd-curses && alias wic=wicd-curses
  161. null type wicd-cli && alias wil="wicd-cli -y -l | head"
  162. #alias wicn="wicd-cli -y -c -n"
  163. wicn(){
  164. if test $# -eq 0
  165. then
  166. local num
  167. wicd-cli -y -l | head
  168. echo -n "input num: "
  169. read num
  170. test -n "$num" && wicd-cli -y -c -n $num
  171. else
  172. wicd-cli -y -c -n $1
  173. fi
  174. }
  175. for f in /usr/share/vim/vimcurrent/macros/less.sh \
  176. /usr/share/vim/vim73/macros/less.sh \
  177. /usr/share/vim/vim72/macros/less.sh
  178. do
  179. test -f $f && alias vl=$f && break
  180. done
  181. null type yaourt && alias yt=yaourt
  182. null type pacman-color && {
  183. alias pacman=pacman-color
  184. export pacman_program=pacman-color # used by pacmatic
  185. export PACMAN=pacman-color # used by yaourt
  186. }
  187. null type pacmatic && {
  188. alias pacman="pacmatic"
  189. export PACMAN="pacmatic"
  190. }
  191. null type apt-get && {
  192. alias aupgrade="sudo apt-get autoremove --yes && \
  193. sudo apt-get update --yes && sudo apt-get upgrade --yes"
  194. alias aptin="apt-get install"
  195. alias aptsearch="apt-cache search"
  196. alias aptshow="apt-cache show"
  197. }
  198. null type port && {
  199. alias port="port -v"
  200. alias pupgrade="sudo port -v selfupdate && \
  201. { sudo port -v upgrade outdated; }"
  202. }
  203. if iscygwin; then
  204. null type windate || \
  205. alias windate="/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%'"
  206. alias cygsu="cygstart /cygwinsetup.exe"
  207. alias emacs="CYGWIN=tty emacs -nw"
  208. alias ls="ls -CFG $(iswindows || test "$TERM" = dumb || echo --color=auto)"
  209. fi
  210. g(){
  211. if test $# -eq 0 && null type git-info
  212. then
  213. git info
  214. else
  215. git "$@"
  216. fi
  217. }
  218. if null type _git
  219. then
  220. # enable programmable completion for g
  221. complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
  222. || complete -o default -o nospace -F _git g
  223. fi
  224. alias setup.py="sudo python3 setup.py install --record files.txt"
  225. clock(){
  226. local tformat="%Y/%m/%d %H:%M:%S %z"
  227. cal
  228. while true
  229. do
  230. printf "\\r`date "+${tformat}"`"
  231. sleep 1
  232. done
  233. }
  234. man(){
  235. env \
  236. LESS_TERMCAP_mb=$(printf "\e[1;35m") \
  237. LESS_TERMCAP_md=$(printf "\e[1;31m") \
  238. LESS_TERMCAP_me=$(printf "\e[0m") \
  239. LESS_TERMCAP_se=$(printf "\e[0m") \
  240. LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
  241. LESS_TERMCAP_ue=$(printf "\e[0m") \
  242. LESS_TERMCAP_us=$(printf "\e[1;32m") \
  243. man "$@"
  244. }
  245. scr(){
  246. local _tformat="%Y%m%d-%H%M%S%z"
  247. local _file=`date +${_tformat}`.script
  248. SCRIPT=${_file} script ${_file} "$@"
  249. }
  250. netwait(){
  251. while ! ping -c 1 -t 1 example.com
  252. do
  253. true
  254. done
  255. echo network works.
  256. }
  257. cd(){
  258. if test $# -eq 0
  259. then
  260. pushd ~/ >/dev/null
  261. elif test $1 = -
  262. then
  263. local pwd="$PWD"
  264. command cd $OLDPWD
  265. pushd -n "$pwd" >/dev/null # stack last dir
  266. elif ! test -d "$1"
  267. then
  268. echo `basename ${SHELL}`: cd: "$1": No such file or directory 1>&2
  269. return 1
  270. else
  271. pushd "$1" >/dev/null
  272. fi
  273. __dirs_rm_dup "$PWD"
  274. echo "$PWD"
  275. }
  276. __dirs_rm_dup(){
  277. for d in "$@"
  278. do
  279. local next="$(__realpath --strip "$d")"
  280. for l in $(\dirs -v -l | cut -d $'\n' -f 2- | \
  281. \grep -x " *[0-9]\+ \+${next}" | \grep -o "^ *[0-9]\+ " | tac)
  282. do
  283. popd +$l -n >/dev/null
  284. done
  285. done
  286. }
  287. __realpath(){
  288. if type realpath >/dev/null 2>&1
  289. then
  290. command realpath "$@"
  291. else
  292. while ! test -d $1
  293. do
  294. shift
  295. done
  296. local d="$OLDPWD"
  297. command cd "$1"
  298. echo "$PWD"
  299. command cd "$d"
  300. fi
  301. }
  302. dh(){
  303. if test $# -eq 0
  304. then
  305. dirs -v -l
  306. else
  307. local dir="$(dirs -v -l | \grep "^ *$1 \+" | sed "s/^ *[0-9]* *//g")"
  308. cd "$dir"
  309. fi
  310. }
  311. input(){
  312. local foo
  313. stty -echo
  314. read foo
  315. stty echo
  316. echo $foo
  317. }
  318. tmux(){
  319. if test $# -eq 0
  320. then
  321. (cd ~; command tmux start;)
  322. if command tmux has -t main
  323. then
  324. command tmux attach -t main
  325. else
  326. (cd ~; command tmux new -s main;)
  327. fi
  328. else
  329. command tmux "$@"
  330. fi
  331. }
  332. mcrypt-stream(){
  333. test $# -eq 2 || return 1
  334. case $1 in
  335. en)
  336. mcrypt --key $2 | base64 ;;
  337. de)
  338. base64 -d | mcrypt -d --key $2 ;;
  339. esac
  340. }
  341. gpg-stream(){
  342. test $# -eq 2 || return 1
  343. case $1 in
  344. en)
  345. gpg --passphrase $2 -c --batch |base64 ;;
  346. de)
  347. base64 -d|gpg --passphrase $2 -d --batch ;;
  348. esac
  349. }
  350. dgpg(){
  351. if test "$1" = help || test -z "$2"
  352. then
  353. echo "dgpg: dgpg <en|de> <src-suffix> [<dst-suffix>]" 1>&2
  354. return
  355. fi
  356. local srcs="$2"
  357. local dsts="$3"
  358. test -z "$dsts" && dsts="${srcs}.out"
  359. local pw
  360. echo -n "dgpg pw: "
  361. read -s pw
  362. echo ""
  363. test -z "$pw" && return 1
  364. for f in *${srcs}
  365. do
  366. local d="$(basename "$f" "${srcs}")${dsts}"
  367. echo -n "Processing $f to $d..."
  368. if test -d "$f"
  369. then
  370. echo "`printf 'failed (%s is directory)' $f`"
  371. elif test -f "$d"
  372. then
  373. echo "`printf 'failed (%s is already exists)' $d`"
  374. elif <"$f" gpg-stream $1 $pw >"$d" 2>/dev/null
  375. then
  376. echo "done"
  377. else
  378. echo "failed"
  379. test -f "$d" && rm "$d"
  380. fi
  381. done
  382. }
  383. alias enst="gpg-stream en"
  384. alias dest="gpg-stream de"
  385. showinfo(){
  386. echo "Japanese letters are 表示可能"
  387. __try_exec diskinfo
  388. ! isdarwin && test -n "${DISPLAY}" && {
  389. __try_exec xrandr | \grep --color=never ^Screen
  390. }
  391. iswindows || __try_exec finger $USER
  392. LANG=C __try_exec id
  393. __try_exec xset q
  394. }
  395. x(){
  396. if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  397. #mkdir -p ~/.my/log
  398. # nohup startx >~/.my/log/xorg.log 2>&1 &
  399. # exit
  400. exec startx
  401. else
  402. echo "X cant be started! Another X is already running?" 1>&2
  403. fi
  404. }
  405. bak(){
  406. for file in "$@"
  407. do
  408. cp -v ${file} ${file}.bak
  409. done
  410. }
  411. di(){
  412. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  413. then
  414. local diffcmd=colordiff
  415. else
  416. local diffcmd=diff
  417. fi
  418. ${diffcmd} -u "$@" | ${PAGER}
  419. }
  420. tb(){
  421. local tb="$HOME/.my/tb"
  422. mkdir -p "$tb"
  423. for file in "$@"
  424. do
  425. mv -t "$tb" "$file"
  426. done
  427. }
  428. mkcd(){
  429. mkdir -p $1
  430. cd $1
  431. }
  432. if test -n "$TMUX" && null type reattach-to-user-namespace
  433. then
  434. alias pbpaste="reattach-to-user-namespace pbpaste"
  435. alias pbcopy="reattach-to-user-namespace pbcopy"
  436. fi
  437. catclip(){
  438. if iswindows
  439. then
  440. cat /dev/clipboard | tr -d \\r
  441. elif isdarwin
  442. then
  443. pbpaste
  444. else
  445. xclip -o -selection "clipboard"
  446. fi
  447. }
  448. setclip(){
  449. if test $# -eq 0
  450. then
  451. exec 3<&0
  452. else
  453. exec 3<<__EOF__
  454. `cat "$@"`
  455. __EOF__
  456. fi
  457. if iswindows
  458. then
  459. 0<&3 sed -e 's/$/\r/' | tee /dev/clipboard
  460. elif isdarwin
  461. then
  462. pbcopy 0<&3
  463. else
  464. 0<&3 xclip -i -f -selection "primary" | \
  465. xclip -i -f -selection "clipboard"
  466. fi
  467. exec 3<&-
  468. }
  469. open_file(){
  470. if iswindows
  471. then
  472. cmd.exe //c start "" "$@"
  473. elif isdarwin
  474. then
  475. touch "$@"
  476. open "$@"
  477. elif islinux
  478. then
  479. touch "$@"
  480. if null type pcmanfm; then
  481. LC_MESSAGES= pcmanfm "$@"
  482. else
  483. LC_MESSAGES= xdg-open "$@" &
  484. fi
  485. else
  486. cat "$@"
  487. fi
  488. }
  489. o(){
  490. if test $# -eq 0
  491. then
  492. open_file .
  493. else
  494. for f in "$@"
  495. do
  496. open_file "$(realpath "$f")"
  497. done
  498. fi
  499. }
  500. convmv-sjis2utf8-test(){
  501. convmv -r -f sjis -t utf8 *
  502. }
  503. convmv-sjis2utf8-notest(){
  504. convmv -r -f sjis -t utf8 * --notest
  505. }
  506. #Change ANSI Colors
  507. _chengecolors(){
  508. echo -e \
  509. "\e]P0000000" \
  510. "\e]P1cd0000" \
  511. "\e]P200cd00" \
  512. "\e]P3cdcd00" \
  513. "\e]P41e90ff" \
  514. "\e]P5cd00cd" \
  515. "\e]P600cdcd" \
  516. "\e]P7353535" \
  517. "\e]P8666666" \
  518. "\e]P9ff9999" \
  519. "\e]Pa99ff99" \
  520. "\e]Pbffff99" \
  521. "\e]Pc9999ff" \
  522. "\e]Pdff99ff" \
  523. "\e]Pe99ffff" \
  524. "\e]Pfffffff"
  525. }
  526. # printf "\e]P7353535" \
  527. _colors(){
  528. echo -e \
  529. "\e[30mBlack" \
  530. "\e[31mRed" \
  531. "\e[32mGreen" \
  532. "\e[33mYellow" \
  533. "\e[34mBlue" \
  534. "\e[35mMagenta" \
  535. "\e[36mCyan" \
  536. "\e[37mWhite"
  537. echo -e \
  538. "\e[30;1mBright Black" \
  539. "\e[31;1mBright Red" \
  540. "\e[32;1mBright Green" \
  541. "\e[33;1mBright Yellow" \
  542. "\e[34;1mBright Blue" \
  543. "\e[35;1mBright Magenta" \
  544. "\e[36;1mBright Cyan" \
  545. "\e[37;1mBright White\n" \
  546. "\e[0m"
  547. }
  548. winln(){
  549. # for windose make link (actually junction)
  550. if test $# -eq 0
  551. then
  552. {
  553. echo "usage: winln TARGET LINK_NAME"
  554. echo "Create a link to TARGET with the name LINK_NAME \
  555. (that is, TARGET must already exist)."
  556. echo "About other features run 'junction'."
  557. } 1>&2
  558. return 1
  559. else
  560. junction "$2" "$1"
  561. fi
  562. }
  563. __my_moc_state(){
  564. type mocp >/dev/null 2>&1 || return
  565. test "`mocp -Q %state 2>/dev/null`" == PLAY || return
  566. printf "$1" "`mocp -Q %title 2>/dev/null`"
  567. }
  568. __my_parse_svn_branch() {
  569. local LANG=C
  570. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  571. local svn_repository_root=$(svn info 2>/dev/null | \
  572. sed -ne 's#^Repository Root: ##p')
  573. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | \
  574. awk '{print $1}'
  575. }
  576. __my_svn_ps1(){
  577. if svn status >/dev/null 2>&1
  578. then
  579. local svn_branch=$(__my_parse_svn_branch)
  580. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  581. fi
  582. }
  583. __my_battery_status(){
  584. local dir=/sys/class/power_supply/BAT0
  585. if test -d $dir && test -r $dir/status && test -r $dir/charge_full && \
  586. test -r $dir/charge_now
  587. then
  588. local st=$(cat $dir/status)
  589. local full=$(cat $dir/charge_full)
  590. local now=$(cat $dir/charge_now)
  591. local rate=$(expr $now \* 100 / $full)
  592. printf "$1" "${st}:${rate}%"
  593. fi
  594. }
  595. alias bat='__my_battery_status %s\\n'
  596. ip-address(){
  597. type ip >/dev/null 2>&1 || return 1
  598. local ip=$(LANG=C ip addr show scope global | \
  599. \grep --color=never --only-matching 'inet [^ ]*' | cut -d " " -f 2)
  600. test -n "$ip" && printf $1 $ip
  601. }
  602. __my_ps1_script(){
  603. local last=$?
  604. test -n "$SCRIPT" && echo "${__my_c5}SCR${__my_cdef} "
  605. return $last
  606. }
  607. __my_ps1_scale(){
  608. local last=$?
  609. printf "${LINES}x${COLUMNS}"
  610. return $last
  611. }
  612. __my_ps1_tmux(){
  613. local last=$?
  614. null type tmux || return $last
  615. local tmuxc="$(tmux display -p '#S:#I:#W.#P' 2>/dev/null)"
  616. test -n "$TMUX" && echo "[TMUX:$tmuxc]"
  617. return $last
  618. }
  619. __my_ps1_moc(){
  620. local last=$?
  621. __my_moc_state "[MOC:%s]"
  622. return $last
  623. }
  624. for f in /usr/share/git/git-prompt.sh \
  625. /opt/local/share/doc/git-core/contrib/completion/git-prompt.sh
  626. do
  627. test -r $f && . $f && break
  628. done
  629. GIT_PS1_SHOWDIRTYSTATE=t
  630. GIT_PS1_SHOWUPSTREAM=t
  631. __my_ps1_git(){
  632. local last=$?
  633. null type __git_ps1 || return $last
  634. null __gitdir || return $last
  635. __git_ps1 "[GIT:$(__try_exec git config --get user.name):%s]"
  636. return $last
  637. }
  638. __my_ps1_ipaddr(){
  639. local last=$?
  640. ! iswindows && ip-address [Addr:%s]
  641. return $last
  642. }
  643. __my_ps1_bttry(){
  644. local last=$?
  645. local bst="${TMP}/batterystatus"
  646. if test -z "$DISPLAY" && ! iswindows
  647. then
  648. test -f $bst && local bstr="$(cat $bst)"
  649. test -n "$bstr" && ! echo $bstr | grep 100 >/dev/null 2>&1 && \
  650. echo "[Battery:$bstr]"
  651. __my_battery_status %s >$bst &
  652. fi
  653. return $last
  654. }
  655. __my_ps1_dirs(){
  656. dirs | wc -l
  657. }
  658. __my_ps1_jobs(){
  659. jobs | wc -l
  660. }
  661. if test "$TERM" != dumb
  662. then
  663. __my_c1="\[\e[1;31m\]" # color for PWD
  664. __my_c2="\[\e[0;36m\]" # color for user
  665. __my_c3="\[\e[1;30m\]" # color for OLDPWD
  666. if test "`hostname`" = arch-aspireone; then __my_c4="\[\e[1;34m\]"
  667. elif test "`hostname`" = darwin-mba.local; then __my_c4="\[\e[1;33m\]"
  668. elif test "`hostname`" = newkiwi; then __my_c4="\[\e[1;35m\]"
  669. else __my_c4="\[\e[1;32m\]" # color for ::
  670. fi
  671. __my_c5="\[\e[30;47m\]" # color for SCR
  672. __my_cdef="\[\e[0m\]"
  673. fi
  674. export _LAST_STATUS=$?
  675. __my_export_last_status(){
  676. export _LAST_STATUS=$?
  677. echo $_LAST_STATUS
  678. return $_LAST_STATUS
  679. }
  680. _PS1="\
  681. ${__my_c4}:: ${__my_cdef}[${__my_c2}\u@\H${__my_cdef}:${__my_c1}\w/${__my_cdef}]\$(__my_ps1_git)\$(__my_ps1_bttry)\$(__my_ps1_ipaddr)\$(__my_ps1_moc)\n\
  682. ${__my_c4}:: ${__my_cdef}l${SHLVL}n\#j\js\$? $(__my_ps1_scale) \D{%T} $(__my_ps1_script)\$ "
  683. PS1=$_PS1
  684. __my_set_title(){
  685. title="$(echo $@)"
  686. case $TERM in
  687. (rxvt*|xterm*|aterm|screen*)
  688. test -t 1 &&
  689. test -n "$DISPLAY" &&
  690. test -z "$EMACS" &&
  691. echo -n -e "\033]0;${title}\007"
  692. ;;
  693. esac
  694. }
  695. PROMPT_COMMAND="__my_set_title \${USER}@\${HOSTNAME}\ \${PWD}"
  696. # copied from https://wiki.archlinux.org/index.php/X_resources
  697. invader(){
  698. # ANSI color scheme script featuring Space Invaders
  699. #
  700. # Original: http://crunchbanglinux.org/forums/post/126921/#p126921
  701. # Modified by lolilolicon
  702. #
  703. f=3 b=4
  704. for j in f b; do
  705. for i in {0..7}; do
  706. printf -v $j$i %b "\e[${!j}${i}m"
  707. done
  708. done
  709. bld=$'\e[1m'
  710. rst=$'\e[0m'
  711. cat << EOF
  712. $f1 ▀▄ ▄▀ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4 ▀▄ ▄▀ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  713. $f1 ▄█▀███▀█▄ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4 ▄█▀███▀█▄ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  714. $f1█▀███████▀█ $f2▀▀███▀▀███▀▀ $f3▀█▀██▀█▀ $f4█▀███████▀█ $f5▀▀███▀▀███▀▀ $f6▀█▀██▀█▀$rst
  715. $f1▀ ▀▄▄ ▄▄▀ ▀ $f2 ▀█▄ ▀▀ ▄█▀ $f3▀▄ ▄▀ $f4▀ ▀▄▄ ▄▄▀ ▀ $f5 ▀█▄ ▀▀ ▄█▀ $f6▀▄ ▄▀$rst
  716. $bld$f1▄ ▀▄ ▄▀ ▄ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4▄ ▀▄ ▄▀ ▄ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  717. $bld$f1█▄█▀███▀█▄█ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4█▄█▀███▀█▄█ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  718. $bld$f1▀█████████▀ $f2▀▀▀██▀▀██▀▀▀ $f3▀▀█▀▀█▀▀ $f4▀█████████▀ $f5▀▀▀██▀▀██▀▀▀ $f6▀▀█▀▀█▀▀$rst
  719. $bld$f1 ▄▀ ▀▄ $f2▄▄▀▀ ▀▀ ▀▀▄▄ $f3▄▀▄▀▀▄▀▄ $f4 ▄▀ ▀▄ $f5▄▄▀▀ ▀▀ ▀▀▄▄ $f6▄▀▄▀▀▄▀▄$rst
  720. $f7▌$rst
  721. $f7▌$rst
  722. $f7 ▄█▄ $rst
  723. $f7▄█████████▄$rst
  724. $f7▀▀▀▀▀▀▀▀▀▀▀$rst
  725. EOF
  726. }
  727. #/etc/lsb-release