No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

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