Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

846 righe
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. test -n "$1" && pf="${1}-"
  261. local _tformat="%Y%m%d-%H%M%S%z"
  262. local _file="${HOME}/${pf}`date +${_tformat}`.script"
  263. SCRIPT=${_file} script ${_file} "$@"
  264. }
  265. netwait(){
  266. while ! ping -c 1 -t 1 example.com
  267. do
  268. true
  269. done
  270. echo network works.
  271. }
  272. cd(){
  273. if test $# -eq 0
  274. then
  275. pushd ~/ >/dev/null
  276. elif test "$1" = -
  277. then
  278. local pwd="$PWD"
  279. command cd "$OLDPWD"
  280. pushd -n "$pwd" >/dev/null # stack last dir
  281. elif ! test -d "$1"
  282. then
  283. echo `basename ${SHELL}`: cd: "$1": No such file or directory 1>&2
  284. return 1
  285. else
  286. pushd "$1" >/dev/null
  287. fi
  288. __dirs_rm_dup "$PWD"
  289. echo "$PWD"
  290. }
  291. __dirs_rm_dup(){
  292. for d in "$@"
  293. do
  294. local next="$(__realpath --strip "$d")"
  295. for l in $(\dirs -v -l | cut -d $'\n' -f 2- | \
  296. \grep -x " *[0-9]\+ \+${next}" | \grep -o "^ *[0-9]\+ " | tac)
  297. do
  298. popd +$l -n >/dev/null
  299. done
  300. done
  301. }
  302. __realpath(){
  303. if type realpath >/dev/null 2>&1
  304. then
  305. command realpath "$@"
  306. else
  307. while ! test -d $1
  308. do
  309. shift
  310. done
  311. local d="$OLDPWD"
  312. command cd "$1"
  313. echo "$PWD"
  314. command cd "$d"
  315. fi
  316. }
  317. dh(){
  318. if test $# -eq 0
  319. then
  320. dirs -v -l
  321. else
  322. local dir="$(dirs -v -l | \grep "^ *$1 \+" | sed "s/^ *[0-9]* *//g")"
  323. cd "$dir"
  324. fi
  325. }
  326. input(){
  327. local foo
  328. stty -echo
  329. read foo
  330. stty echo
  331. echo $foo
  332. }
  333. tmux(){
  334. if test $# -eq 0
  335. then
  336. (cd ~; command tmux start;)
  337. if command tmux has -t main
  338. then
  339. command tmux attach -t main
  340. else
  341. (cd ~; command tmux new -s main;)
  342. fi
  343. else
  344. command tmux "$@"
  345. fi
  346. }
  347. mcrypt-stream(){
  348. test $# -eq 2 || return 1
  349. case $1 in
  350. en)
  351. mcrypt --key $2 | base64 ;;
  352. de)
  353. base64 -d | mcrypt -d --key $2 ;;
  354. esac
  355. }
  356. gpg-stream(){
  357. test $# -eq 2 || return 1
  358. case $1 in
  359. en)
  360. gpg --passphrase $2 -c --batch |base64 ;;
  361. de)
  362. base64 -d|gpg --passphrase $2 -d --batch ;;
  363. esac
  364. }
  365. dgpg(){
  366. if test "$1" = help || test -z "$2"
  367. then
  368. echo "dgpg: dgpg <en|de> <src-suffix> [<dst-suffix>]" 1>&2
  369. return
  370. fi
  371. local srcs="$2"
  372. local dsts="$3"
  373. test -z "$dsts" && dsts="${srcs}.out"
  374. local pw
  375. echo -n "dgpg pw: "
  376. read -s pw
  377. echo ""
  378. test -z "$pw" && return 1
  379. for f in *${srcs}
  380. do
  381. local d="$(basename "$f" "${srcs}")${dsts}"
  382. echo -n "Processing $f to $d..."
  383. if test -d "$f"
  384. then
  385. echo "`printf 'failed (%s is directory)' $f`"
  386. elif test -f "$d"
  387. then
  388. echo "`printf 'failed (%s is already exists)' $d`"
  389. elif <"$f" gpg-stream $1 $pw >"$d" 2>/dev/null
  390. then
  391. echo "done"
  392. else
  393. echo "failed"
  394. test -f "$d" && rm "$d"
  395. fi
  396. done
  397. }
  398. alias enst="gpg-stream en"
  399. alias dest="gpg-stream de"
  400. showinfo(){
  401. echo "Japanese letters are 表示可能"
  402. __try_exec diskinfo
  403. ! isdarwin && test -n "${DISPLAY}" && {
  404. __try_exec xrandr | \grep --color=never ^Screen
  405. }
  406. iswindows || __try_exec finger $USER
  407. LANG=C __try_exec id
  408. __try_exec xset q
  409. }
  410. x(){
  411. if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  412. #mkdir -p ~/.my/log
  413. # nohup startx >~/.my/log/xorg.log 2>&1 &
  414. # exit
  415. exec startx
  416. else
  417. echo "X cant be started! Another X is already running?" 1>&2
  418. fi
  419. }
  420. bak(){
  421. for file in "$@"
  422. do
  423. cp -v ${file} ${file}.bak
  424. done
  425. }
  426. di(){
  427. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  428. then
  429. local diffcmd=colordiff
  430. else
  431. local diffcmd=diff
  432. fi
  433. ${diffcmd} -u "$@" | ${PAGER}
  434. }
  435. tb(){
  436. local tb="$HOME/.my/tb"
  437. mkdir -p "$tb"
  438. for file in "$@"
  439. do
  440. mv -t "$tb" "$file"
  441. done
  442. }
  443. mkcd(){
  444. mkdir -p $1
  445. cd $1
  446. }
  447. if test -n "$TMUX" && null type reattach-to-user-namespace
  448. then
  449. alias pbpaste="reattach-to-user-namespace pbpaste"
  450. alias pbcopy="reattach-to-user-namespace pbcopy"
  451. fi
  452. catclip(){
  453. if iswindows
  454. then
  455. cat /dev/clipboard | tr -d \\r
  456. elif isdarwin
  457. then
  458. pbpaste
  459. else
  460. xclip -o -selection "clipboard"
  461. fi
  462. }
  463. setclip(){
  464. if test $# -eq 0
  465. then
  466. exec 3<&0
  467. else
  468. exec 3<<__EOF__
  469. `cat "$@"`
  470. __EOF__
  471. fi
  472. if iswindows
  473. then
  474. 0<&3 sed -e 's/$/\r/' | tee /dev/clipboard
  475. elif isdarwin
  476. then
  477. pbcopy 0<&3
  478. else
  479. 0<&3 xclip -i -f -selection "primary" | \
  480. xclip -i -f -selection "clipboard"
  481. fi
  482. exec 3<&-
  483. }
  484. open_file(){
  485. if iswindows
  486. then
  487. cmd.exe //c start "" "$@"
  488. elif isdarwin
  489. then
  490. touch "$@"
  491. open "$@"
  492. elif islinux
  493. then
  494. touch "$@"
  495. if null type pcmanfm; then
  496. LC_MESSAGES= pcmanfm "$@"
  497. else
  498. LC_MESSAGES= xdg-open "$@" &
  499. fi
  500. else
  501. cat "$@"
  502. fi
  503. }
  504. o(){
  505. if test $# -eq 0
  506. then
  507. open_file .
  508. else
  509. for f in "$@"
  510. do
  511. open_file "$(realpath "$f")"
  512. done
  513. fi
  514. }
  515. convmv-sjis2utf8-test(){
  516. convmv -r -f sjis -t utf8 *
  517. }
  518. convmv-sjis2utf8-notest(){
  519. convmv -r -f sjis -t utf8 * --notest
  520. }
  521. #Change ANSI Colors
  522. _chengecolors(){
  523. echo -e \
  524. "\e]P0000000" \
  525. "\e]P1cd0000" \
  526. "\e]P200cd00" \
  527. "\e]P3cdcd00" \
  528. "\e]P41e90ff" \
  529. "\e]P5cd00cd" \
  530. "\e]P600cdcd" \
  531. "\e]P7353535" \
  532. "\e]P8666666" \
  533. "\e]P9ff9999" \
  534. "\e]Pa99ff99" \
  535. "\e]Pbffff99" \
  536. "\e]Pc9999ff" \
  537. "\e]Pdff99ff" \
  538. "\e]Pe99ffff" \
  539. "\e]Pfffffff"
  540. }
  541. # printf "\e]P7353535" \
  542. _colors(){
  543. echo -e \
  544. "\e[30mBlack" \
  545. "\e[31mRed" \
  546. "\e[32mGreen" \
  547. "\e[33mYellow" \
  548. "\e[34mBlue" \
  549. "\e[35mMagenta" \
  550. "\e[36mCyan" \
  551. "\e[37mWhite"
  552. echo -e \
  553. "\e[30;1mBright Black" \
  554. "\e[31;1mBright Red" \
  555. "\e[32;1mBright Green" \
  556. "\e[33;1mBright Yellow" \
  557. "\e[34;1mBright Blue" \
  558. "\e[35;1mBright Magenta" \
  559. "\e[36;1mBright Cyan" \
  560. "\e[37;1mBright White\n" \
  561. "\e[0m"
  562. }
  563. winln(){
  564. # for windose make link (actually junction)
  565. if test $# -eq 0
  566. then
  567. {
  568. echo "usage: winln TARGET LINK_NAME"
  569. echo "Create a link to TARGET with the name LINK_NAME \
  570. (that is, TARGET must already exist)."
  571. echo "About other features run 'junction'."
  572. } 1>&2
  573. return 1
  574. else
  575. junction "$2" "$1"
  576. fi
  577. }
  578. __my_moc_state(){
  579. type mocp >/dev/null 2>&1 || return
  580. test "`mocp -Q %state 2>/dev/null`" == PLAY || return
  581. printf "$1" "`mocp -Q %title 2>/dev/null`"
  582. }
  583. __my_parse_svn_branch() {
  584. local LANG=C
  585. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  586. local svn_repository_root=$(svn info 2>/dev/null | \
  587. sed -ne 's#^Repository Root: ##p')
  588. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | \
  589. awk '{print $1}'
  590. }
  591. __my_svn_ps1(){
  592. if svn status >/dev/null 2>&1
  593. then
  594. local svn_branch=$(__my_parse_svn_branch)
  595. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  596. fi
  597. }
  598. __my_battery_status(){
  599. local dir=/sys/class/power_supply/BAT0
  600. if test -d $dir && test -r $dir/status && test -r $dir/charge_full && \
  601. test -r $dir/charge_now
  602. then
  603. local st=$(cat $dir/status)
  604. local full=$(cat $dir/charge_full)
  605. local now=$(cat $dir/charge_now)
  606. local rate=$(expr $now \* 100 / $full)
  607. printf "$1" "${st}:${rate}%"
  608. fi
  609. }
  610. alias bat='__my_battery_status %s\\n'
  611. ip-address(){
  612. type ip >/dev/null 2>&1 || return 1
  613. local ip=$(LANG=C ip addr show scope global | \
  614. \grep --color=never --only-matching 'inet [^ ]*' | cut -d " " -f 2)
  615. test -n "$ip" && printf $1 $ip
  616. }
  617. __my_ps1_script(){
  618. local last=$?
  619. test -n "$SCRIPT" && echo "${__my_c5}SCR${__my_cdef} "
  620. return $last
  621. }
  622. __my_ps1_scale(){
  623. local last=$?
  624. printf "${LINES}x${COLUMNS}"
  625. return $last
  626. }
  627. __my_ps1_tmux(){
  628. local last=$?
  629. null type tmux || return $last
  630. local tmuxc="$(tmux display -p '#S:#I:#W.#P' 2>/dev/null)"
  631. test -n "$TMUX" && echo "[TMUX:$tmuxc]"
  632. return $last
  633. }
  634. __my_ps1_moc(){
  635. local last=$?
  636. __my_moc_state "[MOC:%s]"
  637. return $last
  638. }
  639. for f in /usr/share/git/git-prompt.sh \
  640. /opt/local/share/doc/git-core/contrib/completion/git-prompt.sh
  641. do
  642. test -r $f && . $f && break
  643. done
  644. GIT_PS1_SHOWDIRTYSTATE=t
  645. GIT_PS1_SHOWUPSTREAM=t
  646. __my_ps1_git(){
  647. local last=$?
  648. null type __git_ps1 || return $last
  649. null __gitdir || return $last
  650. __git_ps1 "[GIT:$(__try_exec git config --get user.name):%s]"
  651. return $last
  652. }
  653. __my_ps1_ipaddr(){
  654. local last=$?
  655. ! iswindows && ip-address [Addr:%s]
  656. return $last
  657. }
  658. __my_ps1_bttry(){
  659. local last=$?
  660. local bst="${TMP}/batterystatus"
  661. if test -z "$DISPLAY" && ! iswindows
  662. then
  663. test -f $bst && local bstr="$(cat $bst)"
  664. test -n "$bstr" && ! echo $bstr | grep 100 >/dev/null 2>&1 && \
  665. echo "[Battery:$bstr]"
  666. __my_battery_status %s >$bst &
  667. fi
  668. return $last
  669. }
  670. __my_ps1_dirs(){
  671. dirs | wc -l
  672. }
  673. __my_ps1_jobs(){
  674. jobs | wc -l
  675. }
  676. if test "$TERM" != dumb
  677. then
  678. __my_c1="\[\e[0;33m\]" # color for PWD
  679. __my_c2="\[\e[0;36m\]" # color for user
  680. __my_c3="\[\e[1;30m\]" # color for OLDPWD
  681. if test "`hostname`" = arch-aspireone; then __my_c4="\[\e[1;34m\]"
  682. elif test "`hostname`" = darwin-mba.local; then __my_c4="\[\e[1;31m\]"
  683. elif test "`hostname`" = newkiwi; then __my_c4="\[\e[1;35m\]"
  684. else __my_c4="\[\e[1;32m\]" # color for ::
  685. fi
  686. __my_c5="\[\e[30;47m\]" # color for SCR
  687. __my_cdef="\[\e[0m\]"
  688. fi
  689. export _LAST_STATUS=$?
  690. __my_export_last_status(){
  691. export _LAST_STATUS=$?
  692. echo $_LAST_STATUS
  693. return $_LAST_STATUS
  694. }
  695. _PS1="\
  696. ${__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\
  697. ${__my_c4}:: ${__my_cdef}l${SHLVL}n\#j\js\$? $(__my_ps1_scale) \D{%T} $(__my_ps1_script)\$ "
  698. PS1=$_PS1
  699. __my_set_screen_title(){
  700. if test -n "$TMUX" && test -z "$INSIDE_EMACS"
  701. then
  702. echo -ne "\033k$1\033\\"
  703. fi
  704. }
  705. __my_set_title(){
  706. case $TERM in
  707. (rxvt*|xterm*|aterm|screen*)
  708. title="$(echo $@)"
  709. test -t 1 &&
  710. test -n "$DISPLAY" &&
  711. test -z "$EMACS" &&
  712. echo -n -e "\033]0;${title}\007"
  713. ;;
  714. esac
  715. }
  716. PROMPT_COMMAND="__my_set_title \${USER}@\${HOSTNAME}\:\${PWD};
  717. __my_set_screen_title \$(basename \"\$PWD\")/"
  718. # copied from https://wiki.archlinux.org/index.php/X_resources
  719. invader(){
  720. # ANSI color scheme script featuring Space Invaders
  721. #
  722. # Original: http://crunchbanglinux.org/forums/post/126921/#p126921
  723. # Modified by lolilolicon
  724. #
  725. f=3 b=4
  726. for j in f b; do
  727. for i in {0..7}; do
  728. printf -v $j$i %b "\e[${!j}${i}m"
  729. done
  730. done
  731. bld=$'\e[1m'
  732. rst=$'\e[0m'
  733. cat << EOF
  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. $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. $bld$f1 ▄▀ ▀▄ $f2▄▄▀▀ ▀▀ ▀▀▄▄ $f3▄▀▄▀▀▄▀▄ $f4 ▄▀ ▀▄ $f5▄▄▀▀ ▀▀ ▀▀▄▄ $f6▄▀▄▀▀▄▀▄$rst
  742. $f7▌$rst
  743. $f7▌$rst
  744. $f7 ▄█▄ $rst
  745. $f7▄█████████▄$rst
  746. $f7▀▀▀▀▀▀▀▀▀▀▀$rst
  747. EOF
  748. }
  749. #/etc/lsb-release