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.
 
 
 
 
 
 

841 lines
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 pacmatic && {
  193. alias pacman="pacmatic"
  194. export PACMAN="pacmatic"
  195. }
  196. null type apt-get && {
  197. alias aupgrade="sudo apt-get autoremove --yes && \
  198. sudo apt-get update --yes && sudo apt-get upgrade --yes"
  199. alias aptin="apt-get install"
  200. alias aptsearch="apt-cache search"
  201. alias aptshow="apt-cache show"
  202. }
  203. null type port && {
  204. alias port="port -v"
  205. alias pupgrade="sudo port -v selfupdate && \
  206. { sudo port -v upgrade outdated; }"
  207. }
  208. if iscygwin; then
  209. null type windate || \
  210. alias windate="/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%'"
  211. alias cygsu="cygstart /cygwinsetup.exe"
  212. alias emacs="CYGWIN=tty emacs -nw"
  213. alias ls="ls -CFG $(iswindows || test "$TERM" = dumb || echo --color=auto)"
  214. fi
  215. g(){
  216. if test $# -eq 0 && null type git-info
  217. then
  218. git info
  219. else
  220. git "$@"
  221. fi
  222. }
  223. if null type _git
  224. then
  225. # enable programmable completion for g
  226. complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
  227. || complete -o default -o nospace -F _git g
  228. fi
  229. alias setup.py="sudo python3 setup.py install --record files.txt"
  230. ssh(){
  231. __my_set_screen_title ssh
  232. command ssh "$@"
  233. }
  234. clk(){
  235. local tformat="%Y/%m/%d %H:%M:%S %z"
  236. cal
  237. while true
  238. do
  239. printf "\\r`date "+${tformat}"`"
  240. sleep 1
  241. done
  242. }
  243. man(){
  244. env \
  245. LESS_TERMCAP_mb=$(printf "\e[1;35m") \
  246. LESS_TERMCAP_md=$(printf "\e[1;31m") \
  247. LESS_TERMCAP_me=$(printf "\e[0m") \
  248. LESS_TERMCAP_se=$(printf "\e[0m") \
  249. LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
  250. LESS_TERMCAP_ue=$(printf "\e[0m") \
  251. LESS_TERMCAP_us=$(printf "\e[1;32m") \
  252. man "$@"
  253. }
  254. scr(){
  255. test -n "$1" && pf="${1}-"
  256. local _tformat="%Y%m%d-%H%M%S%z"
  257. local _file="${HOME}/${pf}`date +${_tformat}`.script"
  258. SCRIPT=${_file} script ${_file} "$@"
  259. }
  260. netwait(){
  261. while ! ping -c 1 -t 1 example.com
  262. do
  263. true
  264. done
  265. echo network works.
  266. }
  267. cd(){
  268. if test $# -eq 0
  269. then
  270. pushd ~/ >/dev/null
  271. elif test "$1" = -
  272. then
  273. local pwd="$PWD"
  274. command cd "$OLDPWD"
  275. pushd -n "$pwd" >/dev/null # stack last dir
  276. elif ! test -d "$1"
  277. then
  278. echo `basename ${SHELL}`: cd: "$1": No such file or directory 1>&2
  279. return 1
  280. else
  281. pushd "$1" >/dev/null
  282. fi
  283. __dirs_rm_dup "$PWD"
  284. echo "$PWD"
  285. }
  286. __dirs_rm_dup(){
  287. for d in "$@"
  288. do
  289. local next="$(__realpath --strip "$d")"
  290. for l in $(\dirs -v -l | cut -d $'\n' -f 2- | \
  291. \grep -x " *[0-9]\+ \+${next}" | \grep -o "^ *[0-9]\+ " | tac)
  292. do
  293. popd +$l -n >/dev/null
  294. done
  295. done
  296. }
  297. __realpath(){
  298. if type realpath >/dev/null 2>&1
  299. then
  300. command realpath "$@"
  301. else
  302. while ! test -d $1
  303. do
  304. shift
  305. done
  306. local d="$OLDPWD"
  307. command cd "$1"
  308. echo "$PWD"
  309. command cd "$d"
  310. fi
  311. }
  312. dh(){
  313. if test $# -eq 0
  314. then
  315. dirs -v -l
  316. else
  317. local dir="$(dirs -v -l | \grep "^ *$1 \+" | sed "s/^ *[0-9]* *//g")"
  318. cd "$dir"
  319. fi
  320. }
  321. input(){
  322. local foo
  323. stty -echo
  324. read foo
  325. stty echo
  326. echo $foo
  327. }
  328. tmux(){
  329. if test $# -eq 0
  330. then
  331. (cd ~; command tmux start;)
  332. if command tmux has -t main
  333. then
  334. command tmux attach -t main
  335. else
  336. (cd ~; command tmux new -s main;)
  337. fi
  338. else
  339. command tmux "$@"
  340. fi
  341. }
  342. mcrypt-stream(){
  343. test $# -eq 2 || return 1
  344. case $1 in
  345. en)
  346. mcrypt --key $2 | base64 ;;
  347. de)
  348. base64 -d | mcrypt -d --key $2 ;;
  349. esac
  350. }
  351. gpg-stream(){
  352. test $# -eq 2 || return 1
  353. case $1 in
  354. en)
  355. gpg --passphrase $2 -c --batch |base64 ;;
  356. de)
  357. base64 -d|gpg --passphrase $2 -d --batch ;;
  358. esac
  359. }
  360. dgpg(){
  361. if test "$1" = help || test -z "$2"
  362. then
  363. echo "dgpg: dgpg <en|de> <src-suffix> [<dst-suffix>]" 1>&2
  364. return
  365. fi
  366. local srcs="$2"
  367. local dsts="$3"
  368. test -z "$dsts" && dsts="${srcs}.out"
  369. local pw
  370. echo -n "dgpg pw: "
  371. read -s pw
  372. echo ""
  373. test -z "$pw" && return 1
  374. for f in *${srcs}
  375. do
  376. local d="$(basename "$f" "${srcs}")${dsts}"
  377. echo -n "Processing $f to $d..."
  378. if test -d "$f"
  379. then
  380. echo "`printf 'failed (%s is directory)' $f`"
  381. elif test -f "$d"
  382. then
  383. echo "`printf 'failed (%s is already exists)' $d`"
  384. elif <"$f" gpg-stream $1 $pw >"$d" 2>/dev/null
  385. then
  386. echo "done"
  387. else
  388. echo "failed"
  389. test -f "$d" && rm "$d"
  390. fi
  391. done
  392. }
  393. alias enst="gpg-stream en"
  394. alias dest="gpg-stream de"
  395. showinfo(){
  396. echo "Japanese letters are 表示可能"
  397. __try_exec diskinfo
  398. ! isdarwin && test -n "${DISPLAY}" && {
  399. __try_exec xrandr | \grep --color=never ^Screen
  400. }
  401. iswindows || __try_exec finger $USER
  402. LANG=C __try_exec id
  403. __try_exec xset q
  404. }
  405. x(){
  406. if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  407. #mkdir -p ~/.my/log
  408. # nohup startx >~/.my/log/xorg.log 2>&1 &
  409. # exit
  410. exec startx
  411. else
  412. echo "X cant be started! Another X is already running?" 1>&2
  413. fi
  414. }
  415. bak(){
  416. for file in "$@"
  417. do
  418. cp -v ${file} ${file}.bak
  419. done
  420. }
  421. di(){
  422. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  423. then
  424. local diffcmd=colordiff
  425. else
  426. local diffcmd=diff
  427. fi
  428. ${diffcmd} -u "$@" | ${PAGER}
  429. }
  430. tb(){
  431. local tb="$HOME/.my/tb"
  432. mkdir -p "$tb"
  433. for file in "$@"
  434. do
  435. mv -t "$tb" "$file"
  436. done
  437. }
  438. mkcd(){
  439. mkdir -p $1
  440. cd $1
  441. }
  442. if test -n "$TMUX" && null type reattach-to-user-namespace
  443. then
  444. alias pbpaste="reattach-to-user-namespace pbpaste"
  445. alias pbcopy="reattach-to-user-namespace pbcopy"
  446. fi
  447. catclip(){
  448. if iswindows
  449. then
  450. cat /dev/clipboard | tr -d \\r
  451. elif isdarwin
  452. then
  453. pbpaste
  454. else
  455. xclip -o -selection "clipboard"
  456. fi
  457. }
  458. setclip(){
  459. if test $# -eq 0
  460. then
  461. exec 3<&0
  462. else
  463. exec 3<<__EOF__
  464. `cat "$@"`
  465. __EOF__
  466. fi
  467. if iswindows
  468. then
  469. 0<&3 sed -e 's/$/\r/' | tee /dev/clipboard
  470. elif isdarwin
  471. then
  472. pbcopy 0<&3
  473. else
  474. 0<&3 xclip -i -f -selection "primary" | \
  475. xclip -i -f -selection "clipboard"
  476. fi
  477. exec 3<&-
  478. }
  479. open_file(){
  480. if iswindows
  481. then
  482. cmd.exe //c start "" "$@"
  483. elif isdarwin
  484. then
  485. touch "$@"
  486. open "$@"
  487. elif islinux
  488. then
  489. touch "$@"
  490. if null type pcmanfm; then
  491. LC_MESSAGES= pcmanfm "$@"
  492. else
  493. LC_MESSAGES= xdg-open "$@" &
  494. fi
  495. else
  496. cat "$@"
  497. fi
  498. }
  499. o(){
  500. if test $# -eq 0
  501. then
  502. open_file .
  503. else
  504. for f in "$@"
  505. do
  506. open_file "$(realpath "$f")"
  507. done
  508. fi
  509. }
  510. convmv-sjis2utf8-test(){
  511. convmv -r -f sjis -t utf8 *
  512. }
  513. convmv-sjis2utf8-notest(){
  514. convmv -r -f sjis -t utf8 * --notest
  515. }
  516. #Change ANSI Colors
  517. _chengecolors(){
  518. echo -e \
  519. "\e]P0000000" \
  520. "\e]P1cd0000" \
  521. "\e]P200cd00" \
  522. "\e]P3cdcd00" \
  523. "\e]P41e90ff" \
  524. "\e]P5cd00cd" \
  525. "\e]P600cdcd" \
  526. "\e]P7353535" \
  527. "\e]P8666666" \
  528. "\e]P9ff9999" \
  529. "\e]Pa99ff99" \
  530. "\e]Pbffff99" \
  531. "\e]Pc9999ff" \
  532. "\e]Pdff99ff" \
  533. "\e]Pe99ffff" \
  534. "\e]Pfffffff"
  535. }
  536. # printf "\e]P7353535" \
  537. _colors(){
  538. echo -e \
  539. "\e[30mBlack" \
  540. "\e[31mRed" \
  541. "\e[32mGreen" \
  542. "\e[33mYellow" \
  543. "\e[34mBlue" \
  544. "\e[35mMagenta" \
  545. "\e[36mCyan" \
  546. "\e[37mWhite"
  547. echo -e \
  548. "\e[30;1mBright Black" \
  549. "\e[31;1mBright Red" \
  550. "\e[32;1mBright Green" \
  551. "\e[33;1mBright Yellow" \
  552. "\e[34;1mBright Blue" \
  553. "\e[35;1mBright Magenta" \
  554. "\e[36;1mBright Cyan" \
  555. "\e[37;1mBright White\n" \
  556. "\e[0m"
  557. }
  558. winln(){
  559. # for windose make link (actually junction)
  560. if test $# -eq 0
  561. then
  562. {
  563. echo "usage: winln TARGET LINK_NAME"
  564. echo "Create a link to TARGET with the name LINK_NAME \
  565. (that is, TARGET must already exist)."
  566. echo "About other features run 'junction'."
  567. } 1>&2
  568. return 1
  569. else
  570. junction "$2" "$1"
  571. fi
  572. }
  573. __my_moc_state(){
  574. type mocp >/dev/null 2>&1 || return
  575. test "`mocp -Q %state 2>/dev/null`" == PLAY || return
  576. printf "$1" "`mocp -Q %title 2>/dev/null`"
  577. }
  578. __my_parse_svn_branch() {
  579. local LANG=C
  580. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  581. local svn_repository_root=$(svn info 2>/dev/null | \
  582. sed -ne 's#^Repository Root: ##p')
  583. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | \
  584. awk '{print $1}'
  585. }
  586. __my_svn_ps1(){
  587. if svn status >/dev/null 2>&1
  588. then
  589. local svn_branch=$(__my_parse_svn_branch)
  590. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  591. fi
  592. }
  593. __my_battery_status(){
  594. local dir=/sys/class/power_supply/BAT0
  595. if test -d $dir && test -r $dir/status && test -r $dir/charge_full && \
  596. test -r $dir/charge_now
  597. then
  598. local st=$(cat $dir/status)
  599. local full=$(cat $dir/charge_full)
  600. local now=$(cat $dir/charge_now)
  601. local rate=$(expr $now \* 100 / $full)
  602. printf "$1" "${st}:${rate}%"
  603. fi
  604. }
  605. alias bat='__my_battery_status %s\\n'
  606. ip-address(){
  607. type ip >/dev/null 2>&1 || return 1
  608. local ip=$(LANG=C ip addr show scope global | \
  609. \grep --color=never --only-matching 'inet [^ ]*' | cut -d " " -f 2)
  610. test -n "$ip" && printf $1 $ip
  611. }
  612. __my_ps1_script(){
  613. local last=$?
  614. test -n "$SCRIPT" && echo "${__my_c5}SCR${__my_cdef} "
  615. return $last
  616. }
  617. __my_ps1_scale(){
  618. local last=$?
  619. printf "${LINES}x${COLUMNS}"
  620. return $last
  621. }
  622. __my_ps1_tmux(){
  623. local last=$?
  624. null type tmux || return $last
  625. local tmuxc="$(tmux display -p '#S:#I:#W.#P' 2>/dev/null)"
  626. test -n "$TMUX" && echo "[TMUX:$tmuxc]"
  627. return $last
  628. }
  629. __my_ps1_moc(){
  630. local last=$?
  631. __my_moc_state "[MOC:%s]"
  632. return $last
  633. }
  634. for f in /usr/share/git/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="\
  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. PS1=$_PS1
  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\")/"
  713. # copied from https://wiki.archlinux.org/index.php/X_resources
  714. invader(){
  715. # ANSI color scheme script featuring Space Invaders
  716. #
  717. # Original: http://crunchbanglinux.org/forums/post/126921/#p126921
  718. # Modified by lolilolicon
  719. #
  720. f=3 b=4
  721. for j in f b; do
  722. for i in {0..7}; do
  723. printf -v $j$i %b "\e[${!j}${i}m"
  724. done
  725. done
  726. bld=$'\e[1m'
  727. rst=$'\e[0m'
  728. cat << EOF
  729. $f1 ▀▄ ▄▀ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4 ▀▄ ▄▀ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  730. $f1 ▄█▀███▀█▄ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4 ▄█▀███▀█▄ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  731. $f1█▀███████▀█ $f2▀▀███▀▀███▀▀ $f3▀█▀██▀█▀ $f4█▀███████▀█ $f5▀▀███▀▀███▀▀ $f6▀█▀██▀█▀$rst
  732. $f1▀ ▀▄▄ ▄▄▀ ▀ $f2 ▀█▄ ▀▀ ▄█▀ $f3▀▄ ▄▀ $f4▀ ▀▄▄ ▄▄▀ ▀ $f5 ▀█▄ ▀▀ ▄█▀ $f6▀▄ ▄▀$rst
  733. $bld$f1▄ ▀▄ ▄▀ ▄ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4▄ ▀▄ ▄▀ ▄ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
  734. $bld$f1█▄█▀███▀█▄█ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4█▄█▀███▀█▄█ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
  735. $bld$f1▀█████████▀ $f2▀▀▀██▀▀██▀▀▀ $f3▀▀█▀▀█▀▀ $f4▀█████████▀ $f5▀▀▀██▀▀██▀▀▀ $f6▀▀█▀▀█▀▀$rst
  736. $bld$f1 ▄▀ ▀▄ $f2▄▄▀▀ ▀▀ ▀▀▄▄ $f3▄▀▄▀▀▄▀▄ $f4 ▄▀ ▀▄ $f5▄▄▀▀ ▀▀ ▀▀▄▄ $f6▄▀▄▀▀▄▀▄$rst
  737. $f7▌$rst
  738. $f7▌$rst
  739. $f7 ▄█▄ $rst
  740. $f7▄█████████▄$rst
  741. $f7▀▀▀▀▀▀▀▀▀▀▀$rst
  742. EOF
  743. }
  744. #/etc/lsb-release