選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

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