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.
 
 
 
 
 
 

814 lines
18 KiB

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