You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shrc 30 KiB

12 years ago
11 years ago
11 years ago
9 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
4 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
6 years ago
6 years ago
6 years ago
10 years ago
6 years ago
12 years ago
4 years ago
4 years ago
12 years ago
12 years ago
12 years ago
11 years ago
8 years ago
12 years ago
12 years ago
12 years ago
10 years ago
12 years ago
10 years ago
12 years ago
6 years ago
12 years ago
12 years ago
9 years ago
11 years ago
11 years ago
11 years ago
12 years ago
12 years ago
10 years ago
12 years ago
12 years ago
12 years ago
10 years ago
12 years ago
11 years ago
11 years ago
12 years ago
11 years ago
12 years ago
11 years ago
10 years ago
12 years ago
12 years ago
12 years ago
12 years ago
11 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
4 years ago
11 years ago
10 years ago
10 years ago
12 years ago
12 years ago
12 years ago
11 years ago
8 years ago
8 years ago
12 years ago
12 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
4 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
10 years ago
12 years ago
10 years ago
12 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
4 years ago
4 years ago
11 years ago
12 years ago
12 years ago
12 years ago
4 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
11 years ago
10 years ago
11 years ago
12 years ago
11 years ago
10 years ago
12 years ago
12 years ago
12 years ago
11 years ago
4 years ago
10 years ago
11 years ago
12 years ago
4 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  1. #!/bin/sh
  2. # TODO: decide the naming scheme of variables (global, local, ...)
  3. expr "$-" : '^.*i' >/dev/null || return
  4. ##########################################
  5. __shrc_lock=/tmp/shrc_lock.$USER.$$
  6. test -f "$__shrc_lock" && return
  7. touch "$__shrc_lock"
  8. ##########################################
  9. null(){
  10. "$@" >/dev/null 2>&1
  11. }
  12. __safe_run(){
  13. type $1 >/dev/null 2>&1 && "$@"
  14. }
  15. __match(){
  16. # __match str word
  17. # return 0 if word is found in str
  18. expr "$1" : ".*$2.*" >/dev/null
  19. }
  20. __lf=$'\n'
  21. __cr=$'\r'
  22. test -n "$TMP" || export TMP=/tmp/${USER}-tmp
  23. mkdir -p "$TMP"
  24. __homerun="$HOME/.var/run"
  25. mkdir -p "$__homerun"
  26. ##########################
  27. # system type
  28. gnu_coreutils=false # for mac
  29. null ls --version && gnu_coreutils=true
  30. inbash=false
  31. inzsh=false
  32. if test -n "$BASH_VERSION"
  33. then
  34. inbash=true
  35. elif test -n "$ZSH_VERSION"
  36. then
  37. inzsh=true
  38. fi
  39. #################################
  40. # file pathes:
  41. # shrc: Path to this file
  42. if $inbash
  43. then
  44. __shrc="$BASH_SOURCE"
  45. elif $inzsh
  46. then
  47. __shrc="$0"
  48. fi
  49. #########################
  50. # system detection
  51. __system_shrc="$__homerun/system.shrc"
  52. if test -f "$__system_shrc"
  53. then
  54. . "$__system_shrc"
  55. else
  56. ismsys=false
  57. iscygwin=false
  58. iswindows=false
  59. isdarwin=false
  60. isfreebsd=false
  61. isbsd=false
  62. islinux=false
  63. # $OSTYPE is another choice. which is better?
  64. # NOTE: sh on FreeBSD does not define OSTYPE
  65. case `uname` in
  66. MINGW*) ismsys=true ;;
  67. CYGWIN*) iscygwin=true ;;
  68. Darwin*) isdarwin=true ;;
  69. FreeBSD*) isfreebsd=true ;;
  70. Linux*) islinux=true ;;
  71. esac
  72. ($ismsys || $iscygwin) && iswindows=true
  73. # is this true?
  74. ($isdarwin || $isfreebsd) && isbsd=true
  75. # dump system detection result
  76. cat <<__EOC__ >"$__system_shrc"
  77. #!/bin/sh
  78. # $__system_shrc
  79. ismsys=$ismsys
  80. iscygwin=$iscygwin
  81. iswindows=$iswindows
  82. isdarwin=$isdarwin
  83. isfreebsd=$isfreebsd
  84. isbsd=$isbsd
  85. islinux=$islinux
  86. __EOC__
  87. fi
  88. $ismsys && export HOSTNAME
  89. # adhoc fix for ansible on cygwin
  90. # http://blog.s-uni.net/2013/08/27/ansible-running-on-cygwin/
  91. if $iscygwin
  92. then
  93. export ANSIBLE_SSH_ARGS="-o ControlMaster=no"
  94. fi
  95. ##########################
  96. # Terminal setups
  97. if ! $iswindows && null type stty
  98. then
  99. stty stop undef # unbind C-s to stop displaying output
  100. # stty erase '^h'
  101. fi
  102. # Zsh specific preferences
  103. # http://www.clear-code.com/blog/2011/9/5.html
  104. if $inzsh
  105. then
  106. bindkey -e
  107. # http://zsh.sourceforge.net/Guide/zshguide06.html#l147
  108. autoload compinit; compinit
  109. # supress cycle by tab
  110. unsetopt auto_menu
  111. # unsetopt correct
  112. setopt complete_aliases
  113. setopt auto_list
  114. setopt bash_auto_list
  115. setopt magic_equal_subst
  116. setopt list_types
  117. # what is the difference of these two?
  118. setopt auto_param_slash
  119. setopt mark_dirs
  120. zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
  121. zstyle ':completion:*' format '%B%d%b'
  122. zstyle ':completion:*' group-name ''
  123. zstyle ':completion:*' use-cache yes
  124. # zstyle ':completion:*:cd:*' tag-order local-directories
  125. zstyle ':completion:*' completer _complete _bash_completions \
  126. _history
  127. # zstyle ':completion:*:*:cd:*' completer
  128. zstyle ':completion:*' accept-exact-dirs true
  129. zstyle ':completion:*' special-dirs true
  130. autoload colors; colors
  131. # autoload -Uz promptinit
  132. # promptinit
  133. # prompt walters
  134. setopt hist_ignore_dups
  135. setopt hist_ignore_all_dups
  136. setopt hist_save_no_dups
  137. setopt extended_history
  138. setopt share_history
  139. setopt append_history
  140. HISTFILE=$HOME/.zsh-history
  141. HISTSIZE=100000
  142. SAVEHIST=100000
  143. setopt prompt_subst
  144. setopt interactive_comments
  145. fi
  146. ######################
  147. # Print welcome messages
  148. if command -v lolcat >/dev/null
  149. then
  150. alias __safe_lolcat=lolcat
  151. else
  152. alias __safe_lolcat=cat
  153. fi
  154. if command -v cowsay >/dev/null
  155. then
  156. alias __safe_cowsay=cowsay
  157. else
  158. alias __safe_cowsay=cat
  159. fi
  160. command -v fortune >/dev/null && {
  161. fortune | __safe_cowsay | __safe_lolcat
  162. echo
  163. fortune -o | __safe_cowsay | __safe_lolcat
  164. echo
  165. }
  166. uname -a
  167. $iswindows && alias tty="echo cmd.exe"
  168. echo TERM $TERM with $(tput colors) colors using $(tty)
  169. echo umask: `umask -S`
  170. # if null type figlet && null type lolcat
  171. # then
  172. # echo `whoami`@`hostname` | figlet | lolcat
  173. # fi
  174. # echo
  175. if command -v neofetch >/dev/null
  176. then
  177. neofetch
  178. elif command -v screenfetch >/dev/null
  179. then
  180. screenfetch
  181. fi
  182. __safe_run id `whoami`
  183. # echo
  184. ## A bit heavy command
  185. # finger `whoami`
  186. echo
  187. __safe_run w `whoami`
  188. # if null type tmux
  189. # then
  190. # echo
  191. # echo tmux sessions:
  192. # tmux ls 2>/dev/null| sed -e 's/^/ /g'
  193. # echo
  194. # fi
  195. # if test -n "$TMUX"
  196. # then
  197. # tmux display -p \
  198. # 'TMUX #S:#I:#W.#P, client TERM: #{client_termname}' \
  199. # 2>/dev/null
  200. # echo
  201. # fi
  202. if test -n "$__MY_DTACH"
  203. then
  204. echo
  205. echo DSession: Current Session: "`basename "$__MY_DTACH"`"
  206. echo DSession: Press C-^ to Exit.
  207. true
  208. fi
  209. i(){
  210. w
  211. ss -lnp
  212. ps aufx
  213. df -h
  214. top -b -d 1 -n 1
  215. top -b -d 1 -n 1 -a
  216. dstat -taf 1 10
  217. }
  218. ###################################
  219. # some aliases and functions
  220. # __func_name: never used interactively
  221. # _func_name: usually not used interactively
  222. __safe_alias(){
  223. # __safe_alias <name>=<command>
  224. _bin=`expr "$1" : '^[^=]*=\([^ ]*\)'`
  225. test -n "$_bin" && \
  226. null type $_bin && \
  227. alias "$1"
  228. }
  229. $gnu_coreutils && _timeoption=" --time-style=long-iso"
  230. # color prefs
  231. if $gnu_coreutils
  232. then
  233. # http://qiita.com/yuyuchu3333/items/84fa4e051c3325098be3
  234. # gnu coreutils LS_COLORS is used
  235. null type dircolors && eval `dircolors`
  236. _coloroption=" --color=auto"
  237. else
  238. # export LSCOLORS=gxfxcxdxbxegedabagacad
  239. export LSCOLORS=DxGxcxdxCxegedabagacad
  240. export CLICOLOR=1
  241. fi
  242. alias ls="ls -hCF${_coloroption}${_timeoption}"
  243. _timeformat_iso="%Y-%m-%dT%H:%M:%S%z"
  244. _timeformat_rfc2822="%a, %d %b %Y %T %z"
  245. _timeformat_num="%Y%m%d%H%M%S"
  246. alias datenum="date +$_timeformat_num"
  247. alias less="less -FX"
  248. __safe_alias em="emacs -nw"
  249. test -n "$_VI_ALT" && alias vi=$_VI_ALT
  250. alias pstree="LANG=C pstree"
  251. alias cp="cp -v"
  252. alias mv="mv -v"
  253. alias rm="rm -v"
  254. alias mkdir="mkdir -v"
  255. $gnu_coreutils && alias rmdir="rmdir -v"
  256. alias psaux="ps auxww"
  257. alias modest="ionice -c 2 -n 7 nice -n 19"
  258. alias e=exec
  259. __safe_alias e3=e3em
  260. #alias dirs="dirs -v -l | \grep -v \$(printf '%s$' \$PWD)"
  261. alias po=popd
  262. alias pu=pushd
  263. __safe_alias sudoe="sudoedit"
  264. __safe_alias ge="git exec"
  265. __safe_alias make="nice make"
  266. __safe_alias brew="nice brew"
  267. __safe_alias gcc="nice gcc"
  268. __safe_alias go="nice go"
  269. __safe_alias git="nice git"
  270. __safe_alias javac="nice javac -J-Duser.language=en"
  271. __safe_alias ansible-playbook="nice ansible-playbook"
  272. alias rand="echo \$RANDOM"
  273. alias pycalc="python -i -c 'from math import *' "
  274. __safe_alias py3=python3
  275. __safe_alias py2=python2
  276. __safe_alias ipy=ipython
  277. __safe_alias ipy3=ipython3
  278. __safe_alias ipy2=ipython2
  279. __safe_alias rl=rlwrap
  280. __safe_alias igosh=gosh-rl
  281. # Sometimes SHELL cannot be used. For example, when running bash inside zsh
  282. # SHELL is set to be /bin/zsh
  283. if $inbash
  284. then
  285. alias _reloadrc="rm '$__shrc_lock'; exec bash"
  286. elif $inzsh
  287. then
  288. alias _reloadrc="rm '$__shrc_lock'; exec zsh"
  289. else
  290. alias _reloadrc="rm '$__shrc_lock'; exec $SHELL"
  291. fi
  292. # alias mytime="date +%Y%m%d-%H%M%S"
  293. alias sh="ENV=$HOME/.shrc PS1=\$\ PROMPT_COMMAND="" sh"
  294. # some extra utilities
  295. __safe_alias mpg123="mpg123 -C -v --title"
  296. #export PLAYER="mpg123 -C -v --title"
  297. __safe_alias screen="screen -e^z^z"
  298. #alias zcd="cd \`zenity --file-selection --directory\`"
  299. __safe_alias gtags="gtags --verbose"
  300. __safe_alias htags="htags --xhtml --symbol --line-number \
  301. --frame --alphabet --verbose"
  302. __safe_alias au=aunpack
  303. # __safe_alias lv="lv|less"
  304. __safe_alias rs="rsync --progress --itemize-changes --compress"
  305. __safe_alias vagr=vagrant
  306. __safe_alias ztw='twitter set "`zenity --entry --title ztw --text Status:`"'
  307. if $iscygwin
  308. then
  309. __my_wget_options=" --no-check-certificate"
  310. __safe_alias wget="wget $__my_wget_options"
  311. fi
  312. if $isdarwin
  313. then
  314. alias updatedb="LC_ALL=C updatedb"
  315. # do not use locate installed by macports
  316. test -x /usr/bin/locate && alias locate="/usr/bin/locate"
  317. fi
  318. # somehow not work
  319. # typeset -ga chpwd_functions
  320. # chpwd_functions+=pwd
  321. # chpwd(){
  322. # pwd
  323. # }
  324. cd(){
  325. builtin cd "$@" && pwd
  326. }
  327. root(){
  328. if test "`git rev-parse --is-inside-work-tree 2>/dev/null`" = true
  329. then
  330. cd "`git rev-parse --show-toplevel`"
  331. else
  332. cd /
  333. fi
  334. }
  335. __find_latest_vimdir(){
  336. vimdir=/usr/share/vim
  337. if test -d "$vimdir"
  338. then
  339. find "$vimdir" -name 'vim??' -type d | sort | tail -n 1
  340. else
  341. echo ""
  342. fi
  343. }
  344. for f in /usr/share/vim/vimcurrent "`__find_latest_vimdir`"
  345. do
  346. test -n "$f" || continue
  347. f="$f/macros/less.sh"
  348. test -f $f && alias vl=$f && break
  349. done
  350. __safe_alias pa="pacman --color=always"
  351. __safe_alias pa="pacmatic --color=always"
  352. __safe_alias pa="pacapt"
  353. __safe_alias yt=yaourt
  354. # variable for yaourt
  355. null type pacmatic && export PACMAN="pacmatic"
  356. __safe_alias cower="cower --color=auto"
  357. __my_pacman_update_mirrorlist_with_reflector(){
  358. f=/etc/pacman.d/mirrorlist
  359. cmd="$(expr "$(grep -m 1 reflector $f)" : '# With: *\(.*\)')"
  360. if test -z "$cmd"
  361. then
  362. cmd="reflector --verbose --number 5 --sort rate --protocol http --protocol https --save $f"
  363. fi
  364. echo ">>> $cmd ..." 1>&2
  365. sudo sh -c "$cmd" && cat $f
  366. }
  367. null type reflector && test -d /etc/pacman.d && \
  368. alias reflect_mirrorlist=__my_pacman_update_mirrorlist_with_reflector
  369. null type apt-get && {
  370. alias aupgrade="sudo sh -xc 'apt-get autoremove --yes && \
  371. apt-get update --yes && apt-get upgrade --yes'"
  372. alias aptin="apt-get install"
  373. alias aptsearch="apt-cache search"
  374. alias aptshow="apt-cache show"
  375. }
  376. null type port && {
  377. alias port="port -v"
  378. alias pupgrade="sudo sh -xc 'port -v selfupdate && \
  379. port -v upgrade outdated'"
  380. }
  381. if $iscygwin
  382. then
  383. null type windate || \
  384. alias windate="cmd.exe //c 'echo %DATE%-%TIME%'"
  385. # alias cygsu="cygstart /cygwinsetup.exe"
  386. fi
  387. mkpatch(){
  388. if test $# -eq 0
  389. then
  390. echo "usage: mkpatch <olddir> <newdir>"
  391. elif ! test -d "$1"
  392. then
  393. echo "mkpatch: $1 is not a directory"
  394. elif ! test -d "$2"
  395. then
  396. echo "mkpatch: $2 is not a directory"
  397. else
  398. diff -Naur "$1" "$2"
  399. fi
  400. }
  401. __sdcv_less(){
  402. command sdcv -n "$@" | less --quit-if-one-screen
  403. }
  404. command -v sdcv >/dev/null && alias dict=__sdcv_less
  405. __safe_alias g="git "
  406. if null type _git && $inbash
  407. then
  408. # enable programmable completion for g
  409. complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
  410. || complete -o default -o nospace -F _git g
  411. fi
  412. #git svn --help >/dev/null 2>&1 && alias gsvn="git svn"
  413. __safe_alias m=gitmemo
  414. #alias setup.py3="sudo python3 setup.py install --record files.txt"
  415. randomstr(){
  416. len=$1
  417. test -z "$len" && len=8
  418. uuidgen | tr -d - | cut -c 1-len
  419. }
  420. datestr(){
  421. # datestr YYYYMMDDhhmmss
  422. if test -z "$1" || test "$1" = "-h"
  423. then
  424. echo "datestr: usage: datestr <YYYYMMDDhhmmss>"
  425. return 1
  426. fi
  427. # actual format for date command
  428. dfmt="`echo "$1" | \
  429. sed -e 's/YYYY/%Y/g' -e 's/yyyy/%Y/g' -e 's/YY/%y/g' -e 's/yy/%y/g' |\
  430. sed -e 's/MM/%m/g' -e 's/DD/%d/g' -e 's/dd/%d/g' | \
  431. sed -e 's/HH/%H/g' -e 's/hh/%H/g' -e 's/mm/%M/g' -e 's/SS/%S/g' -e 's/ss/%S/g'`"
  432. date +"$dfmt"
  433. }
  434. # ssh(){
  435. # # __my_terminal_title ssh
  436. # command ssh "$@"
  437. # }
  438. __ssh_with_cd(){
  439. # __ssh_with_cd <host> <directory> [<arg> ...]
  440. if test -z "$2"
  441. then
  442. echo "usage: __ssh_with_cd <host> <directory> [<arg> ...]"
  443. return 1
  444. fi
  445. host="$1"
  446. shift
  447. dir="$1"
  448. shift
  449. ssh "$host" "$@" -t "cd \"$dir\"; \$SHELL -l"
  450. }
  451. memo(){
  452. if test -z "$1"
  453. then
  454. _memo="memo.txt"
  455. else
  456. _memo="$1/memo.txt"
  457. fi
  458. $EDITOR "$_memo"
  459. if test -z "`cat "$_memo"`"
  460. then
  461. echo "$_memo is empty. Removing."
  462. rm "$_memo"
  463. fi
  464. }
  465. now(){
  466. ___tformat="%Y/%m/%d %H:%M:%S %z"
  467. cal
  468. REPLY=
  469. printf "\\r`date "+${___tformat}"`"
  470. read -t 1
  471. while test $? -ne 0
  472. do
  473. printf "\\r`date "+${___tformat}"`"
  474. read -t 1
  475. done
  476. }
  477. s(){
  478. if git rev-parse --git-dir >/dev/null 2>&1
  479. then
  480. echo ">> git grep -n $@" 1>&2
  481. git grep -n "$@"
  482. elif which ag >/dev/null 2>&1
  483. then
  484. echo ">> ag --pager=\"$PAGER\" $@" 1>&2
  485. ag --pager="$PAGER" "$@"
  486. elif which ack >/dev/null 2>&1
  487. then
  488. echo ">> ack --pager=\"$PAGER\" $@" 1>&2
  489. ack --pager="$PAGER" "$@"
  490. else
  491. echo \
  492. ">> find . " \
  493. "-path '*/.git' -prune -o" \
  494. "-path '*/.svn' -prune -o" \
  495. "-type f -exec grep -nH -e --color=always $@ {} +" 1>&2
  496. if test $# -eq 0
  497. then
  498. echo "No search word given." 1>&2
  499. return 1
  500. fi
  501. find . \
  502. -path '*/.git' -prune -o \
  503. -path '*/.svn' -prune -o \
  504. -type -f -exec grep -nH -e --color=always "$@" {} + \
  505. | $PAGER
  506. fi
  507. }
  508. MYMANPATH='/usr/lib/erlang/man'
  509. if $inbash || $inzsh
  510. then
  511. man(){
  512. env \
  513. LESS_TERMCAP_mb=$(printf "\e[1;35m") \
  514. LESS_TERMCAP_md=$(printf "\e[1;31m") \
  515. LESS_TERMCAP_me=$(printf "\e[0m") \
  516. LESS_TERMCAP_se=$(printf "\e[0m") \
  517. LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
  518. LESS_TERMCAP_ue=$(printf "\e[0m") \
  519. LESS_TERMCAP_us=$(printf "\e[1;32m") \
  520. MANPATH="`manpath`:$MYMANPATH" \
  521. man "$@"
  522. }
  523. fi
  524. netwait(){
  525. while ! ping -c 1 -t 1 example.com
  526. do
  527. true
  528. done
  529. echo network works.
  530. }
  531. __realpath(){
  532. if type realpath >/dev/null 2>&1
  533. then
  534. command realpath "$@"
  535. else
  536. while ! test -d $1
  537. do
  538. shift
  539. done
  540. (command cd "$d" && echo "$PWD")
  541. # local d="$OLDPWD"
  542. # command cd "$1"
  543. # echo "$PWD"
  544. # command cd "$d"
  545. fi
  546. }
  547. if $isdarwin
  548. then
  549. # I want to use env -u, but darwin env does not provide this option
  550. null type tmux && alias tmux='SHLVL= tmux'
  551. else
  552. null type tmux && alias tmux='env -u SHLVL tmux'
  553. fi
  554. tx(){
  555. tmux start-server
  556. if test -z "$1"
  557. then
  558. echo "usage: tx [<session_name>]"
  559. tmux list-sessions
  560. elif test -z "$TMUX"
  561. then
  562. # -A: attach if already exists
  563. # tmux new-session -A -c "$HOME" -s "$1"
  564. tmux new-session -A -s "$1"
  565. else
  566. # create new session if not exists yet
  567. # tmux has-session -t "$1" || TMUX= tmux new-session -d -c "$HOME" -s "$1"
  568. tmux has-session -t "$1" || TMUX= tmux new-session -d -s "$1"
  569. tmux switch-client -t "$1"
  570. fi
  571. }
  572. __dsession(){
  573. # dt [-h] [<name>] [<command ...>]
  574. __dtach_dir="${TMP}/dtach"
  575. mkdir -p "${__dtach_dir}"
  576. if test -n "${__MY_DTACH}"
  577. then
  578. # if already in dtach session print current session
  579. soc_name="`basename "$__MY_DTACH"`"
  580. echo "Current session: ${soc_name}"
  581. fi
  582. if test -z "$1"
  583. then
  584. # if no arg given show list of sessions
  585. echo "Usage: ds [<session>]"
  586. echo "Sessions:"
  587. ls "${__dtach_dir}"
  588. return 0
  589. elif test "$1" = "-h"
  590. then
  591. echo "dt: usage: dt [-h] [<name>] [<command ...>]" 1>&2
  592. return 1
  593. fi
  594. # set socket name
  595. soc_name="${__dtach_dir}/$1"
  596. shift
  597. if test -n "$__MY_DTACH"
  598. then
  599. echo "dtach session cannot be nested." 1>&2
  600. return 1
  601. elif test -S "$soc_name"
  602. then
  603. dtach -a "$soc_name" -e ^^
  604. elif test -e "$soc_name"
  605. then
  606. echo "dt: File named $soc_name already exists."
  607. return 1
  608. elif test -z "$1"
  609. then
  610. # if no command given invoke current shell
  611. __MY_DTACH="$soc_name" dtach -c "$soc_name" -e ^^ sh -c "$SHELL"
  612. # echo "dt: Socket named $soc_name not exists and no command specified."
  613. # return 1
  614. else
  615. __MY_DTACH="$soc_name" dtach -c "$soc_name" -e ^^ "$@"
  616. fi
  617. }
  618. null type dtach && alias ds=__dsession
  619. scr(){
  620. test -n "$1" && pf="${1}-"
  621. ___tformat="%Y%m%d-%H%M%S%z"
  622. ___file="${PWD}/${pf}`date +${___tformat}`.script"
  623. __MY_SCRIPT=${___file} script ${___file} "$@"
  624. }
  625. dtscr(){
  626. # dtscr <command ...>
  627. if test -z "$1"
  628. then
  629. echo "dtscr: usage: dtscr <command ...>"
  630. return 1
  631. fi
  632. ___cmdstr="`echo $@ | tr ' ' +`"
  633. ___tformat="%Y%m%d-%H%M%S%z"
  634. ___name="${pf}`date +${___tformat}`-${___cmdstr}"
  635. ___scr_file="${HOME}/${___name}.script"
  636. ___dt_dir="${TMP}/dtscr"
  637. mkdir -p "$___dt_dir"
  638. dtach -n "${___dt_dir}/${___name}" script "${___scr_file_}" "$@"
  639. # echo $_name
  640. # echo $_file
  641. }
  642. mcrypt_stream(){
  643. test $# -eq 2 || return 1
  644. case $1 in
  645. en)
  646. mcrypt --key $2 | base64 ;;
  647. de)
  648. base64 -d | mcrypt -d --key $2 ;;
  649. esac
  650. }
  651. gpg_stream(){
  652. test $# -eq 2 || return 1
  653. case $1 in
  654. en)
  655. gpg --passphrase $2 -c --batch |base64 ;;
  656. de)
  657. base64 -d|gpg --passphrase $2 -d --batch ;;
  658. esac
  659. }
  660. dgpg(){
  661. if test "$1" = help || test -z "$2"
  662. then
  663. echo "dgpg: dgpg <en|de> <src-suffix> [<dst-suffix>]" 1>&2
  664. return
  665. fi
  666. ___srcs="$2"
  667. ___dsts="$3"
  668. test -z "$___dsts" && ___dsts="${___srcs}.out"
  669. ___pw=
  670. echo -n "dgpg pw: "
  671. read -s ___pw
  672. echo ""
  673. test -z "$___pw" && return 1
  674. for f in *${___srcs}
  675. do
  676. ___d="$(basename "$f" "${___srcs}")${___dsts}"
  677. echo -n "Processing $f to $___d..."
  678. if test -d "$f"
  679. then
  680. echo "`printf 'failed (%s is directory)' $f`"
  681. elif test -f "$___d"
  682. then
  683. echo "`printf 'failed (%s is already exists)' $___d`"
  684. elif <"$f" gpg_stream $1 $___pw >"$___d" 2>/dev/null
  685. then
  686. echo "done"
  687. else
  688. echo "failed"
  689. test -f "$___d" && rm "$___d"
  690. fi
  691. done
  692. }
  693. alias enst="gpg_stream en"
  694. alias dest="gpg_stream de"
  695. showinfo(){
  696. echo "Japanese letters are 表示可能"
  697. __safe_run diskinfo
  698. ! $isdarwin && test -n "${DISPLAY}" && {
  699. __safe_run xrandr | \grep --color=never ^Screen
  700. }
  701. $iswindows || __safe_run finger $USER
  702. LANG=C __safe_run id
  703. __safe_run xset q
  704. }
  705. x(){
  706. if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  707. #mkdir -p ~/.var/log
  708. # nohup startx >~/.var/log/xorg.log 2>&1 &
  709. # exit
  710. exec startx
  711. else
  712. echo "X cant be started! Another X is already running?" 1>&2
  713. fi
  714. }
  715. bak(){
  716. for file in "$@"
  717. do
  718. cp -v ${file} ${file}.bak
  719. done
  720. }
  721. di(){
  722. if null type git
  723. then
  724. git --git-dir= diff "$@"
  725. ___diffcmd="git --git-dir= diff"
  726. else
  727. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  728. then
  729. ___diffcmd=colordiff
  730. else
  731. ___diffcmd=diff
  732. fi
  733. ${___diffcmd} -u "$@" | ${PAGER}
  734. fi
  735. }
  736. __trash_func(){
  737. __datenum=`date +%Y%m%d-%H%M%S`
  738. __tb="$HOME/.var/tb/$__datenum"
  739. mkdir -p "$__tb"
  740. mv "$@" "$__tb"
  741. }
  742. __safe_alias tb=__trash_func
  743. __safe_alias tb=trash
  744. mkdd(){
  745. _d=`date +%Y%m%d-%H%M%S` && \
  746. mkdir -p "$_d"
  747. }
  748. mkcd(){
  749. if test -z "$1"
  750. then
  751. echo "mkcd: usage: mkcd <dir>"
  752. return 1
  753. elif test -d "$1"
  754. then
  755. echo "Dir \"$1\" already exists."
  756. else
  757. mkdir -p "$1"
  758. echo "Dir \"$1\" created."
  759. fi
  760. cd "$1"
  761. }
  762. mkcdd(){
  763. # make and change date directory
  764. _d=`date +%Y%m%d-%H%M%S` && \
  765. mkcd "$_d"
  766. }
  767. if test -n "$TMUX" && null type reattach-to-user-namespace
  768. then
  769. alias pbpaste="reattach-to-user-namespace pbpaste"
  770. alias pbcopy="reattach-to-user-namespace pbcopy"
  771. fi
  772. __catclip(){
  773. if $iswindows
  774. then
  775. cat /dev/clipboard | tr -d \\r
  776. elif $isdarwin
  777. then
  778. pbpaste
  779. else
  780. xclip -o -selection "clipboard"
  781. fi
  782. }
  783. __setclip(){
  784. if test $# -eq 0
  785. then
  786. exec 3<&0
  787. else
  788. exec 3<<__EOF__
  789. `cat "$@"`
  790. __EOF__
  791. fi
  792. if $iswindows
  793. then
  794. 0<&3 sed -e 's/$/\r/' | tee /dev/clipboard
  795. elif $isdarwin
  796. then
  797. pbcopy 0<&3
  798. else
  799. 0<&3 xclip -i -f -selection "primary" | \
  800. xclip -i -f -selection "clipboard"
  801. fi
  802. exec 3<&-
  803. }
  804. # Now Homebrew 10sr/pkg/bin provides these commands:
  805. # Fallback to aliases if commands are not installed yet
  806. which catclip >/dev/null || alias catclip=__catclip
  807. which setclip >/dev/null || alias setclip=__setclip
  808. convmv_sjis2utf8_test(){
  809. convmv -r -f sjis -t utf8 *
  810. }
  811. convmv_sjis2utf8_notest(){
  812. convmv -r -f sjis -t utf8 * --notest
  813. }
  814. #################################################
  815. ## pastebin services
  816. ## https://wiki.archlinux.org/index.php/List_of_Applications/Internet#Pastebin_clients
  817. sprunge(){
  818. # http://sprunge.us
  819. if test -z "$1"
  820. then
  821. curl -F 'sprunge=<-' http://sprunge.us
  822. else
  823. curl http://sprunge.us/$1
  824. fi
  825. }
  826. dpaste(){
  827. # http://dpaste.de
  828. if test -z "$1"
  829. then
  830. curl -F 'content=<-' https://dpaste.de/api/
  831. echo
  832. else
  833. curl https://dpaste.de/$1/raw/
  834. fi
  835. }
  836. ######################################
  837. ## Prompt Settings
  838. __my_moc_state(){
  839. type mocp >/dev/null 2>&1 || return
  840. test "`mocp -Q %state 2>/dev/null`" = PLAY || return
  841. printf "$1" "`mocp -Q %title 2>/dev/null`"
  842. }
  843. __my_parse_svn_branch() {
  844. ___svn_url=$(LANG=C svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  845. ___svn_repository_root=$(LANG=C svn info 2>/dev/null | \
  846. sed -ne 's#^Repository Root: ##p')
  847. echo ${___svn_url} | sed -e 's#^'"${___svn_repository_root}"'##g' | \
  848. awk '{print $1}'
  849. }
  850. __my_svn_ps1(){
  851. if svn status >/dev/null 2>&1
  852. then
  853. ___svn_branch=$(__my_parse_svn_branch)
  854. test -n "${___svn_branch}" && printf "$1" "{$___svn_branch}"
  855. fi
  856. }
  857. __my_battery_status(){
  858. ___dir=/sys/class/power_supply/BAT0
  859. if test -d $___dir && test -r $___dir/status && test -r $___dir/charge_full && \
  860. test -r $___dir/charge_now
  861. then
  862. ___st=$(cat $___dir/status)
  863. ___full=$(cat $___dir/charge_full)
  864. ___now=$(cat $___dir/charge_now)
  865. ___rate=$(expr "$___now" \* 100 / "$___full")
  866. printf "$1" "${___st}:${___rate}%"
  867. fi
  868. }
  869. __my_ps1_scale(){
  870. if null type stty && ! $ismsys
  871. then
  872. echo "[LxC:`stty size | tr -d $'\n' | tr " " x`]"
  873. fi
  874. }
  875. __my_ps1_tmux(){
  876. null type tmux || return $last
  877. ___tmuxc="$(tmux display -p '#S:#I:#W.#P' 2>/dev/null)"
  878. test -n "$TMUX" && echo "[TMUX:$___tmuxc]"
  879. }
  880. __my_ps1_moc(){
  881. __my_moc_state "[MOC:%s]"
  882. }
  883. for f in /usr/share/git/git-prompt.sh \
  884. /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh \
  885. /usr/local/opt/bash-git-prompt/share/gitprompt.sh \
  886. "`brew --prefix 2>/dev/null`"/etc/bash_completion.d/git-prompt.sh \
  887. /usr/share/git-core/contrib/completion/git-prompt.sh \
  888. /usr/local/share/git-core/contrib/completion/git-prompt.sh \
  889. /etc/bash_completion.d/git-prompt \
  890. /opt/local/share/git-core/git-prompt.sh \
  891. /opt/local/share/doc/git-core/contrib/completion/git-prompt.sh
  892. do
  893. if test -r "$f" && ($inbash || $inzsh)
  894. then
  895. . "$f"
  896. break
  897. fi
  898. done
  899. export GIT_PS1_SHOWDIRTYSTATE=t
  900. export GIT_PS1_SHOWUPSTREAM=t
  901. __my_ps1_git(){
  902. null type __git_ps1 || return $last
  903. null git rev-parse --git-dir >/dev/null 2>&1 || return $last
  904. __git_ps1 "[GIT:$(__safe_run git config --get user.name):%s]"
  905. }
  906. __printf_ipaddr(){
  907. # ipaddress <fmt>
  908. type ip >/dev/null 2>&1 || return 1
  909. ___ip=$(LANG=C ip addr show scope global | \
  910. \grep --color=never --only-matching 'inet [^ ]*' | cut -d " " -f 2)
  911. test -n "$___ip" && printf "$1" $___ip
  912. }
  913. alias addr="__printf_ipaddr '%s'"
  914. __my_ps1_ipaddr(){
  915. ! $iswindows && __printf_ipaddr '[Addr:%s]'
  916. }
  917. __my_ps1_bttry(){
  918. ___bst="$__homerun/batterystatus"
  919. if test -z "$DISPLAY" && ! $iswindows
  920. then
  921. test -f $___bst && ___bstr="$(cat $___bst)"
  922. test -n "$___bstr" && ! echo $___bstr | grep 100 >/dev/null 2>&1 && \
  923. echo "[Battery:${___bstr}]"
  924. __my_battery_status %s >$___bst &
  925. fi
  926. }
  927. __my_ps1_memo(){
  928. test -f memo.txt && echo "m:$(echo $(wc -c memo.txt) | cut -f 1 -d " ")"
  929. }
  930. __my_ps1_dirs(){
  931. dirs | wc -l
  932. }
  933. __my_ps1_jobs(){
  934. # __my_ps1_jobs [<num>]
  935. if test -n "$1"
  936. then
  937. jobs="$1"
  938. else
  939. jobs="`jobs | wc -l`"
  940. fi
  941. if test "$jobs" -gt 0
  942. then
  943. echo "JOBS:$jobs"
  944. fi
  945. }
  946. __my_ps1_dollar(){
  947. if test -z "$SHLVL"
  948. then
  949. printf "$1"
  950. else
  951. perl -e 'while($ARGV[0]-- > 0){print "$ARGV[1]";}' $SHLVL "$1"
  952. fi
  953. }
  954. __my_alert_fail(){
  955. test $laststatus -eq 0 || \
  956. echo "STATUS:${laststatus}"
  957. }
  958. # About ansi escape sequences
  959. # http://archive.linux.or.jp/JF/JFdocs/Bash-Prompt-HOWTO-5.html
  960. # http://www.grapecity.com/japan/powernews/column/clang/047/page02.htm
  961. if $inbash || $inzsh
  962. then
  963. if $inzsh
  964. then
  965. __attr_beg=$'%{\033['
  966. __attr_end='m%}'
  967. else
  968. __attr_beg='\[\033['
  969. __attr_end='m\]'
  970. fi
  971. __color_default="${__attr_beg}0${__attr_end}"
  972. __color_black="${__attr_beg}0;30${__attr_end}"
  973. __color_red="${__attr_beg}0;31${__attr_end}"
  974. __color_green="${__attr_beg}0;32${__attr_end}"
  975. __color_yellow="${__attr_beg}0;33${__attr_end}"
  976. __color_blue="${__attr_beg}0;34${__attr_end}"
  977. __color_magenta="${__attr_beg}0;35${__attr_end}"
  978. __color_cyan="${__attr_beg}0;36${__attr_end}"
  979. __color_white="${__attr_beg}0;37${__attr_end}"
  980. __color_light_black="${__attr_beg}1;30${__attr_end}"
  981. __color_light_red="${__attr_beg}1;31${__attr_end}"
  982. __color_light_green="${__attr_beg}1;32${__attr_end}"
  983. __color_light_yellow="${__attr_beg}1;33${__attr_end}"
  984. __color_light_blue="${__attr_beg}1;34${__attr_end}"
  985. __color_light_magenta="${__attr_beg}1;35${__attr_end}"
  986. __color_light_cyan="${__attr_beg}1;36${__attr_end}"
  987. __color_light_white="${__attr_beg}1;37${__attr_end}"
  988. __color_bg_black="${__attr_beg}40${__attr_end}"
  989. __color_bg_red="${__attr_beg}41${__attr_end}"
  990. __color_bg_green="${__attr_beg}42${__attr_end}"
  991. __color_bg_yellow="${__attr_beg}43${__attr_end}"
  992. __color_bg_blue="${__attr_beg}44${__attr_end}"
  993. __color_bg_magenta="${__attr_beg}45${__attr_end}"
  994. __color_bg_cyan="${__attr_beg}46${__attr_end}"
  995. __color_bg_white="${__attr_beg}47${__attr_end}"
  996. __attr_underline="${__attr_beg}4${__attr_end}"
  997. __attr_reverse="${__attr_beg}7${__attr_end}"
  998. __attr_bold="${__attr_beg}1${__attr_end}"
  999. fi
  1000. # NOTE: tput is another easy way to set colors and background
  1001. # For example, "$(tput setab 4)text$(tput sgr0)" print text with background
  1002. # color blue.
  1003. # http://www.ibm.com/developerworks/jp/linux/aix/library/au-learningtput/index.html
  1004. if test "$TERM" != dumb
  1005. then
  1006. __my_c1="$__attr_bold$__attr_underline" # color for PWD
  1007. __my_c2="$__attr_bold$__attr_underline" # color for user and hostname
  1008. # color for ::
  1009. if test -z "$_HOSTCOLOR_1"
  1010. then
  1011. # default color used by tmux status line
  1012. _HOSTCOLOR_1=green
  1013. fi
  1014. eval "__my_c4=\${__color_light_${_HOSTCOLOR_1}}"
  1015. __my_c5="$__color_black$__color_bg_white" # color for SCR
  1016. __my_cdef="$__color_default"
  1017. fi
  1018. if $inbash
  1019. then
  1020. __my_ps1_sh="[BASH:$BASH_VERSION]"
  1021. elif $inzsh
  1022. then
  1023. __my_ps1_sh="[ZSH:$ZSH_VERSION]"
  1024. fi
  1025. __my_ps1_info1(){
  1026. # first line of PS1
  1027. echo "${__my_ps1_sh}$(__my_ps1_scale)$(__my_ps1_git)$(__my_ps1_bttry)$(__my_ps1_moc)"
  1028. }
  1029. test -n "$__MY_SCRIPT" && \
  1030. __my_ps1_str_scr="SCR"
  1031. test -n "$SSH_CONNECTION" && \
  1032. __my_ps1_str_ssh="SSH"
  1033. test -n "$__MY_DTACH" && \
  1034. __my_ps1_str_dt="DT:`basename "$__MY_DTACH$"`"
  1035. __my_ps1_info2(){
  1036. # second line of PS1
  1037. echo $(__my_ps1_memo) $(__my_ps1_jobs) ${__my_ps1_str_scr} \
  1038. ${__my_ps1_str_ssh} ${__my_ps1_str_dt} $(__my_alert_fail) \
  1039. | sed -e 's/ /|/g'
  1040. }
  1041. __my_ps1_beg="${__my_c4}:: ${__my_cdef}"
  1042. __my_ps1_save_pos="\[\033[s\]"
  1043. __my_ps1_restore_pos="\[\033[u\]"
  1044. __my_ps1_move_rightmost="\[\033[\$(tput cols)C\]"
  1045. __my_ps1_move_15left="\[\033[15D\]"
  1046. # collapse when command line is too long and try to write over this string
  1047. # __my_ps1_right="${__my_ps1_save_pos}${__my_ps1_move_rightmost}"
  1048. # ${__my_ps1_move_15left}\D{%Y/%m/%d %H:%M}${__my_ps1_restore_pos}
  1049. if $inzsh
  1050. then
  1051. PROMPT="\
  1052. ${__my_ps1_beg}[${__my_c2}%n@%M${__my_cdef}:${__my_c1}%~/${__my_cdef}]\$(__my_ps1_info1)
  1053. ${__my_ps1_beg}\$(__my_ps1_info2) $(__my_ps1_dollar %#) "
  1054. RPROMPT="%D{%Y/%m/%d %H:%M}"
  1055. elif $inbash
  1056. then
  1057. PS1="\
  1058. ${__my_ps1_beg}[${__my_c2}\u@\H${__my_cdef}:${__my_c1}\w/${__my_cdef}]\$(__my_ps1_info1)\n\
  1059. ${__my_ps1_beg}\D{%Y/%m/%d %H:%M} \$(__my_ps1_info2)${__my_ps1_right} $(__my_ps1_dollar \\$) "
  1060. else
  1061. true
  1062. # PS1="$(printf $(whoami)@$(hostname)$ )"
  1063. fi
  1064. ###################################
  1065. # set header and titles
  1066. __my_set_header_line(){
  1067. # save current position
  1068. printf "\033[s"
  1069. # move to 0,0
  1070. printf "\033[0;0H"
  1071. # clear curent to eol
  1072. printf "\033[K"
  1073. # inverse color
  1074. printf "\033[7m"
  1075. printf "$1"
  1076. # restore color
  1077. printf "\033[0m"
  1078. # restore saved position
  1079. printf "\033[u"
  1080. }
  1081. __my_set_screen_name(){
  1082. # set window name
  1083. if test -n "$TMUX" && test -z "$INSIDE_EMACS"
  1084. then
  1085. echo -ne "\033k$1\033\\"
  1086. fi
  1087. }
  1088. __my_set_title(){
  1089. case $TERM in
  1090. (rxvt*|xterm*|aterm|screen*)
  1091. test -t 1 &&
  1092. test -z "$EMACS" &&
  1093. echo -n -e "\033]0;$1\007"
  1094. ;;
  1095. esac
  1096. }
  1097. if test -n "$TMUX"
  1098. then
  1099. # running tmux locally
  1100. __terminal_title="\$(basename \${PWD})"
  1101. elif test -n "$SSH_CONNECTION" && expr "$TERM" : '^screen' >/dev/null
  1102. then
  1103. # ssh connect from tmux terminal
  1104. __terminal_title="`whoami`@`hostname`:\$(basename \${PWD})"
  1105. else
  1106. __terminal_title="`whoami`@`hostname`:\${PWD}"
  1107. fi
  1108. if $inzsh
  1109. then
  1110. precmd(){
  1111. laststatus=$?
  1112. eval __my_set_title ${__terminal_title}
  1113. }
  1114. else
  1115. if test -n "$PROMPT_COMMAND" && ! expr "$PROMPT_COMMAND" : '.*; *$' >/dev/null
  1116. then
  1117. PROMPT_COMMAND="${PROMPT_COMMAND};"
  1118. fi
  1119. if test -n "$PROMPT_COMMAND"
  1120. then
  1121. PROMPT_COMMAND="laststatus=\$?;${PROMPT_COMMAND}__my_set_title \"${__terminal_title}\";"
  1122. else
  1123. PROMPT_COMMAND="laststatus=\$?;__my_set_title \"${__terminal_title}\";"
  1124. fi
  1125. fi
  1126. laststatus=0