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