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