Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

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