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.
 
 
 
 
 
 

813 lines
18 KiB

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