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 19 KiB

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