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