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.
 
 
 
 
 
 

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