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.
 
 
 
 
 
 

801 lines
18 KiB

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