Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

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