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