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