您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

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