Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

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