No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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