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.
 
 
 
 
 
 

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