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