Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

bashrc 18 KiB

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