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