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.

il y a 13 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 11 ans
il y a 11 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 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 12 ans
il y a 11 ans
il y a 12 ans
il y a 13 ans
il y a 11 ans
il y a 11 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 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 11 ans
il y a 12 ans
il y a 12 ans
il y a 11 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 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 11 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 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 11 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 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 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 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 11 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 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 11 ans
il y a 12 ans
il y a 11 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 11 ans
il y a 11 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 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 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 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 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 11 ans
il y a 11 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 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 12 ans
il y a 12 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 11 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 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 11 ans
il y a 11 ans
il y a 11 ans
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. #!/bin/sh
  2. expr "$-" : '^.*i' >/dev/null || return
  3. ##########################################
  4. null(){
  5. "$@" >/dev/null 2>&1
  6. }
  7. __safe_run(){
  8. type $1 >/dev/null 2>&1 && "$@"
  9. }
  10. __match(){
  11. # __match str word
  12. # return 0 if word is found in str
  13. expr "$1" : ".*$2.*" >/dev/null
  14. }
  15. #################################
  16. # profile-like setups
  17. # aliases:
  18. # isinteractive: true if the current session is interactive
  19. # issourced: true if this file is sourced from another file (not so assured)
  20. # __firstload: true if this file is sourced for the first time (not so
  21. # assured)
  22. __safe_add_path_r(){
  23. test -d "$1" && PATH="${PATH}:$1"
  24. }
  25. __safe_add_path_l(){
  26. test -d "$1" && PATH="$1:${PATH}"
  27. }
  28. __safe_add_path_l "$HOME/.local/bin"
  29. __safe_add_path_l "$HOME/.local/lib/gems/bin"
  30. __safe_add_path_r "/c/mingw/bin"
  31. __safe_add_path_r "/c/mingw/msys/1.0/bin"
  32. # macports coreutils
  33. # $isdarwin cannot be used it is not defined yet
  34. __safe_add_path_l "/opt/local/bin"
  35. __safe_add_path_l "/opt/local/sbin"
  36. __safe_add_path_l "/opt/local/libexec/gnubin"
  37. __safe_add_path_l \
  38. "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/bin"
  39. test -f "${__dotdir}/rc.py" && export PYTHONSTARTUP="${__dotdir}/rc.py"
  40. test -d "$HOME/.local/lib/python/site-packages" && \
  41. export PYTHONPATH="${PYTHONPATH}:${HOME}/.local/lib/python/site-packages"
  42. export GEM_HOME="$HOME/.local/lib/gems"
  43. export RUBYLIB="$RUBYLIB:$HOME/.local/lib/gems/lib"
  44. # it is not so good
  45. # http://archive.linux.or.jp/JF/JFdocs/Program-Library-HOWTO/shared-libraries.html
  46. # http://superuser.com/questions/324613/installing-a-library-locally-in-home-directory-but-program-doesnt-recognize-it
  47. # without this ENV i cannot run tmux. another way is to use --disable-shared
  48. # when building tmux
  49. if ! __match "$LD_LIBRARY_PATH" "$HOME/.local/lib"
  50. then
  51. export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/.local/lib"
  52. fi
  53. # in my environment powerdown does not work
  54. test -z "$SSH_CONNECTION" && \
  55. type setterm >/dev/null 2>&1 && \
  56. setterm -blank 30 -powersave on # -powerdown 10
  57. #########################
  58. # shrc.common
  59. # this variable must consistent with setup.sh
  60. __shrc_common="$HOME/.shrc.common"
  61. if test -f "$__shrc_common"
  62. then
  63. . "$__shrc_common"
  64. else
  65. echo "$__shrc_common not found."
  66. echo "Run setup.sh first."
  67. return
  68. fi
  69. ##########################
  70. # system type
  71. gnu_coreutils=false # for mac
  72. null ls --version && gnu_coreutils=true
  73. inbash=false
  74. inzsh=false
  75. if test -n "$BASH_VERSION"
  76. then
  77. inbash=true
  78. elif test -n "$ZSH_VERSION"
  79. then
  80. inzsh=true
  81. fi
  82. #################################
  83. # file pathes:
  84. # shrc: Path to this file
  85. if $inbash
  86. then
  87. __shrc="$BASH_SOURCE"
  88. elif $inzsh
  89. then
  90. __shrc="$0"
  91. fi
  92. ##################################
  93. # EnvVal definitions
  94. export LANG=ja_JP.UTF-8
  95. export LC_MESSAGES=C
  96. export LC_TIME=C
  97. export TERMCAP="${TERMCAP}:vb="
  98. $ismsys && export HOSTNAME
  99. # export ENV=~/.shrc
  100. if ! $gnu_coreutils
  101. then
  102. export LSCOLORS=gxfxcxdxbxegedabagacad
  103. else
  104. # http://qiita.com/yuyuchu3333/items/84fa4e051c3325098be3
  105. null type dircolors && eval `dircolors`
  106. fi
  107. if false $iswindows
  108. then
  109. export PAGER='tr -d \\r | less'
  110. else
  111. export PAGER="less"
  112. fi
  113. export LESS="-iRMX"
  114. # Style for lesspipe is defined in esc.style
  115. _src_hilite_lp_path="`which src-hilite-lesspipe.sh 2>/dev/null`"
  116. for f in /usr/share/source-highlight/src-hilite-lesspipe.sh
  117. do
  118. test -z "$_src_hilite_lp_path" && test -e "$f" && _src_hilite_lp_path="$f"
  119. done
  120. test -n "$_src_hilite_lp_path" && export LESSOPEN="| $_src_hilite_lp_path %s"
  121. if null type vim
  122. then
  123. export EDITOR=vim
  124. else
  125. export EDITOR=vi
  126. fi
  127. # export CDPATH=".:~"
  128. export VISUAL="$EDITOR"
  129. export GIT_PAGER="less -FS"
  130. export GIT_EDITOR="$EDITOR"
  131. export GIT_MERGE_AUTOEDIT=no
  132. if test -n "$TMUX" && \
  133. __match $TERM screen && \
  134. __match `tmux display -p '#{client_termname}'` 256color
  135. then
  136. TERM=screen-256color
  137. fi
  138. if test -z "$TMP"
  139. then
  140. if test -n "$TMPDIR"
  141. then
  142. export TMP=$TMPDIR
  143. elif test -n "$TEMP"
  144. then
  145. export TMP="$TEMP"
  146. else
  147. export TMP=/tmp
  148. fi
  149. fi
  150. __match "$TMP" "${USER}-tmp" >/dev/null || export TMP="${TMP}/${USER}-tmp"
  151. export TEMP="$TMP"
  152. test -d "$TMP" || install -d "$TMP"
  153. if ! $iswindows && null type stty
  154. then
  155. stty stop undef # unbind C-s to stop displaying output
  156. # stty erase '^h'
  157. fi
  158. if $iswindows
  159. then
  160. export USER=$USERNAME
  161. fi
  162. if test -d ~/dbx
  163. then
  164. export CHIT_PATH="$HOME/dbx/.chit"
  165. fi
  166. ######################
  167. # Print welcome messages
  168. $iswindows && alias tty="echo cmd.exe"
  169. type fortune >/dev/null 2>&1 && {
  170. fortune
  171. echo
  172. fortune -o
  173. echo
  174. }
  175. uname -a
  176. echo TERM $TERM $(tput colors) colors connected to $(tty), \
  177. running $BASH $BASH_VERSION
  178. if test -n "$TMUX"
  179. then
  180. tmux display -p 'Using tmux #S:#I:#W.#P, client is #{client_termname}' \
  181. 2>/dev/null
  182. echo
  183. fi
  184. ###################################
  185. # some aliases and functions
  186. # __func_name: never used interactively
  187. # _func_name: usually not used interactively
  188. __safe_alias(){
  189. # __safe_alias <name>=<command>
  190. _bin=`expr "$1" : '^[^=]*=\([^ ]*\)'`
  191. test -n "$_bin" && \
  192. null type $_bin && \
  193. alias "$1"
  194. }
  195. ( ! $gnu_coreutils && $isdarwin ) || test "$TERM" = dumb || \
  196. _coloroption=" --color=auto"
  197. ( ! $gnu_coreutils && $isdarwin ) || $iswindows || \
  198. _timeoption=" --time-style=long-iso"
  199. ( ! $gnu_coreutils && $isdarwin ) || _hideoption=" --hide=[A-Z]*" # do not use
  200. _timeformat_iso="%Y-%m-%dT%H:%M:%S%z"
  201. _timeformat_rfc2822="%a, %d %b %Y %T %z"
  202. _timeformat_num="%Y%m%d%H%M%S"
  203. alias datenum="date +$_timeformat_num"
  204. alias ls="ls -hCF${_coloroption}${_timeoption}"
  205. # export GREP_OPTIONS=""
  206. alias gr="grep -n --color=always"
  207. $iswindows && alias grep="grep -n"
  208. # alias ll="ls -l"
  209. # alias la="ls -A"
  210. # alias lla="ls -Al"
  211. alias less="less -F"
  212. __safe_alias em="emacs -nw"
  213. __safe_alias vi=vim
  214. alias pstree="LANG=C pstree"
  215. alias cp="cp -v"
  216. alias mv="mv -v"
  217. alias rm="rm -v"
  218. alias psaux="ps auxww"
  219. alias q=exit
  220. __safe_alias e3=e3em
  221. #alias dirs="dirs -v -l | \grep -v \$(printf '%s$' \$PWD)"
  222. alias po=popd
  223. alias pu=pushd
  224. __safe_alias sudo="sudo " # use aliases through sudo
  225. __safe_alias sudoe="sudoedit"
  226. # __safe_alias halt="sudo halt"
  227. # __safe_alias reboot="sudo reboot"
  228. null type dbus-send && {
  229. alias suspend="dbus-send --system --print-reply --dest=org.freedesktop.UPower \
  230. /org/freedesktop/UPower org.freedesktop.UPower.Suspend"
  231. alias hibernate="dbus-send --system --print-reply --dest=org.freedesktop.UPower \
  232. /org/freedesktop/UPower org.freedesktop.UPower.Hibernate"
  233. }
  234. alias rand="echo \$RANDOM"
  235. __safe_alias xunp="file-roller -h"
  236. __safe_alias pc="sudo \paco -D"
  237. alias pycalc="python -i -c 'from math import *' "
  238. __safe_alias py3=python3
  239. __safe_alias py2=python2
  240. alias _reloadrc="exec \"$SHELL\""
  241. # alias mytime="date +%Y%m%d-%H%M%S"
  242. alias sh="ENV=$HOME/.shrc PS1=\$\ PROMPT_COMMAND="" sh"
  243. # type trash >/dev/null 2>&1 && alias rm=trash
  244. __safe_alias mpg123="mpg123 -C -v --title"
  245. __safe_alias xm="xmms2"
  246. #export PLAYER="mpg123 -C -v --title"
  247. __safe_alias screen="screen -e^z^z"
  248. #alias zcd="cd \`zenity --file-selection --directory\`"
  249. __safe_alias gtags="gtags --verbose"
  250. __safe_alias htags="htags --xhtml --symbol --line-number \
  251. --frame --alphabet --verbose"
  252. __safe_alias au=aunpack
  253. __safe_alias lv="lv|less"
  254. __safe_alias rs="rsync --progress --itemize-changes --compress"
  255. if $iscygwin
  256. then
  257. __my_wget_options=" --no-check-certificate"
  258. __safe_alias wget="wget $__my_wget_options"
  259. fi
  260. if $isdarwin
  261. then
  262. alias updatedb="LC_ALL=C updatedb"
  263. # do not use locate installed by macports
  264. test -x /usr/bin/locate && alias locate="/usr/bin/locate"
  265. fi
  266. cd(){
  267. command cd "$@"
  268. pwd
  269. }
  270. # pad
  271. alias pad=notepad
  272. __safe_alias pad=gedit
  273. __safe_alias pad=leafpad
  274. $isdarwin && alias pad="open -e"
  275. __safe_alias wic=wicd-curses
  276. __safe_alias wil="wicd-cli -y -l | head"
  277. #alias wicn="wicd-cli -y -c -n"
  278. wicn(){
  279. if test $# -eq 0
  280. then
  281. local num
  282. wicd-cli -y -l | head
  283. echo -n "input num: "
  284. read num
  285. test -n "$num" && wicd-cli -y -c -n $num
  286. else
  287. wicd-cli -y -c -n $1
  288. fi
  289. }
  290. __find_latest_vimdir(){
  291. vimdir=/usr/share/vim
  292. if test -d "$vimdir"
  293. then
  294. find "$vimdir" -name 'vim??' -type d | sort | tail -n 1
  295. else
  296. echo ""
  297. fi
  298. }
  299. for f in /usr/share/vim/vimcurrent "`__find_latest_vimdir`"
  300. do
  301. test -n "$f" || continue
  302. f="$f/macros/less.sh"
  303. test -f $f && alias vl=$f && break
  304. done
  305. alias pa=pacapt
  306. __safe_alias yt=yaourt
  307. __safe_alias cower="cower --color=auto"
  308. null type pacmatic && {
  309. alias pacman="pacmatic"
  310. export PACMAN="pacmatic"
  311. }
  312. __my_pacman_update_mirrorlist_with_reflector(){
  313. ml=/etc/pacman.d/mirrorlist
  314. cmd="$(expr "$(grep -m 1 reflector $ml)" : '# With: *\(.*\)')"
  315. if test -z "$cmd"
  316. then
  317. cmd="reflector --verbose -l 5 --sort rate --save $ml"
  318. fi
  319. echo "Running $cmd ..." 1>&2
  320. sudo $cmd
  321. }
  322. null type reflector && test -f /etc/pacman.d/mirrorlist && \
  323. alias reflect_mirrorlist=__my_pacman_update_mirrorlist_with_reflector
  324. null type apt-get && {
  325. alias aupgrade="sudo apt-get autoremove --yes && \
  326. sudo apt-get update --yes && sudo apt-get upgrade --yes"
  327. alias aptin="apt-get install"
  328. alias aptsearch="apt-cache search"
  329. alias aptshow="apt-cache show"
  330. }
  331. null type port && {
  332. alias port="port -v"
  333. alias pupgrade="sudo port -v selfupdate && \
  334. { sudo port -v upgrade outdated; }"
  335. }
  336. if $iscygwin
  337. then
  338. null type windate || \
  339. alias windate="cmd.exe //c 'echo %DATE%-%TIME%'"
  340. # alias cygsu="cygstart /cygwinsetup.exe"
  341. fi
  342. g(){
  343. if test $# -eq 0 && null type git-info
  344. then
  345. git info
  346. else
  347. git -c color.ui=always "$@"
  348. fi
  349. }
  350. if null type _git && $inbash
  351. then
  352. # enable programmable completion for g
  353. complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
  354. || complete -o default -o nospace -F _git g
  355. fi
  356. #git svn --help >/dev/null 2>&1 && alias gsvn="git svn"
  357. __safe_alias m=gitmemo
  358. alias setup.py3="sudo python3 setup.py install --record files.txt"
  359. randomstr(){
  360. len=$1
  361. test -z "$len" && len=8
  362. uuidgen | tr -d - | cut -c 1-len
  363. }
  364. datestr(){
  365. # datestr yyyyMMdd-hhmmss
  366. if test -z "$1" || test "$1" == "-h"
  367. then
  368. echo "datestr: usage: datestr <yyyyMMddhhmmss>"
  369. return 1
  370. fi
  371. dfmt= # actual format for date command
  372. while test -n "$1"
  373. do
  374. fmt="$1"
  375. while test -n "$fmt"
  376. do
  377. case "$fmt" in
  378. yyyy*) # year
  379. dfmt="${dfmt}%Y"
  380. fmt="`echo "$fmt" | cut -c 5-`"
  381. ;;
  382. yy*) # last two digits of year
  383. dfmt="${dfmt}%y"
  384. fmt="`echo "$fmt" | cut -c 3-`"
  385. ;;
  386. MM*) # month (01..12)
  387. dfmt="${dfmt}%m"
  388. fmt="`echo "$fmt" | cut -c 3-`"
  389. ;;
  390. dd*) # day of month (01..12)
  391. dfmt="${dfmt}%d"
  392. fmt="`echo "$fmt" | cut -c 3-`"
  393. ;;
  394. HH* | hh*) # hour (00..23)
  395. dfmt="${dfmt}%H"
  396. fmt="`echo "$fmt" | cut -c 3-`"
  397. ;;
  398. mm*) # minute (00..59)
  399. dfmt="${dfmt}%M"
  400. fmt="`echo "$fmt" | cut -c 3-`"
  401. ;;
  402. ss*) # second (00..60)
  403. dfmt="${dfmt}%S"
  404. fmt="`echo "$fmt" | cut -c 3-`"
  405. ;;
  406. *)
  407. char=`echo "$fmt" | cut -c 1`
  408. dfmt="${dfmt}${char}"
  409. fmt="`echo "$fmt" | cut -c 2-`"
  410. ;;
  411. esac
  412. done
  413. shift
  414. done
  415. date +"$dfmt"
  416. }
  417. ssh(){
  418. __my_set_screen_title ssh
  419. command ssh "$@"
  420. }
  421. __ssh_with_cd(){
  422. # __ssh_with_cd <host> <directory> [<arg> ...]
  423. if test -z "$2"
  424. then
  425. echo "usage: __ssh_with_cd <host> <directory> [<arg> ...]"
  426. return 1
  427. fi
  428. host="$1"
  429. shift
  430. dir="$1"
  431. shift
  432. ssh "$host" "$@" -t "cd \"$dir\"; \$SHELL -l"
  433. }
  434. memo(){
  435. if test -z "$1"
  436. then
  437. $EDITOR memo.txt
  438. else
  439. $EDITOR "$1/memo.txt"
  440. fi
  441. }
  442. now(){
  443. local tformat="%Y/%m/%d %H:%M:%S %z"
  444. cal
  445. REPLY=
  446. printf "\\r`date "+${tformat}"`"
  447. read -t 1
  448. while test $? -ne 0
  449. do
  450. printf "\\r`date "+${tformat}"`"
  451. read -t 1
  452. done
  453. }
  454. s(){
  455. if git rev-parse --git-dir >/dev/null 2>&1
  456. then
  457. echo ">> git grep -n $@" 1>&2
  458. git grep -n "$@"
  459. elif which ag >/dev/null 2>&1
  460. then
  461. echo ">> ag --pager=\"$PAGER\" $@" 1>&2
  462. ag --pager="$PAGER" "$@"
  463. elif which ack >/dev/null 2>&1
  464. then
  465. echo ">> ack --pager=\"$PAGER\" $@" 1>&2
  466. ack --pager="$PAGER" "$@"
  467. else
  468. echo \
  469. ">> find . " \
  470. "-path '*/.git' -prune -o" \
  471. "-path '*/.svn' -prune -o" \
  472. "-type f -exec grep -nH -e --color=always $@ {} +" 1>&2
  473. if test $# -eq 0
  474. then
  475. echo "No search word given." 1>&2
  476. return 1
  477. fi
  478. find . \
  479. -path '*/.git' -prune -o \
  480. -path '*/.svn' -prune -o \
  481. -type -f -exec grep -nH -e --color=always "$@" {} + \
  482. | $PAGER
  483. fi
  484. }
  485. man(){
  486. env \
  487. LESS_TERMCAP_mb=$(printf "\e[1;35m") \
  488. LESS_TERMCAP_md=$(printf "\e[1;31m") \
  489. LESS_TERMCAP_me=$(printf "\e[0m") \
  490. LESS_TERMCAP_se=$(printf "\e[0m") \
  491. LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
  492. LESS_TERMCAP_ue=$(printf "\e[0m") \
  493. LESS_TERMCAP_us=$(printf "\e[1;32m") \
  494. man "$@"
  495. }
  496. netwait(){
  497. while ! ping -c 1 -t 1 example.com
  498. do
  499. true
  500. done
  501. echo network works.
  502. }
  503. __realpath(){
  504. if type realpath >/dev/null 2>&1
  505. then
  506. command realpath "$@"
  507. else
  508. while ! test -d $1
  509. do
  510. shift
  511. done
  512. (command cd "$d" && echo "$PWD")
  513. # local d="$OLDPWD"
  514. # command cd "$1"
  515. # echo "$PWD"
  516. # command cd "$d"
  517. fi
  518. }
  519. tx(){
  520. if test $# -eq 0
  521. then
  522. echo ":: tx <session> to attach."
  523. tmux ls
  524. elif tmux has -t "$1"
  525. then
  526. tmux attach -t "$1"
  527. else
  528. tmux new -s "$1"
  529. fi
  530. }
  531. _tmux_prefs(){
  532. null type tmux || return 1
  533. tmux set -g mode-keys vi
  534. }
  535. dt(){
  536. # dt [<name>] [<command ...>]
  537. __dtach_dir="${TMP}/dtach"
  538. install -d "${__dtach_dir}"
  539. if test -n "${__MY_DTACH}"
  540. then
  541. soc_name="`echo $__MY_DTACH | sed -e "s ^$__dtach_dir/ "`"
  542. echo "Current session: ${soc_name}"
  543. fi
  544. if test -z "$1"
  545. then
  546. echo "Sessions:"
  547. ls "${__dtach_dir}"
  548. return 0
  549. elif test "$1" = "-h"
  550. then
  551. echo "dt: usage: dt <name> [<command ...>]" 1>&2
  552. return 1
  553. fi
  554. soc_name="${__dtach_dir}/$1"
  555. shift
  556. if test -n "$__MY_DTACH"
  557. then
  558. echo "dtach session cannot be nested." 1>&2
  559. return 1
  560. elif test -S "$soc_name"
  561. then
  562. dtach -a "$soc_name" -e ^^
  563. elif test -e "$soc_name"
  564. then
  565. echo "dt: File named $soc_name already exists."
  566. return 1
  567. elif test -z "$1"
  568. then
  569. __MY_DTACH="$soc_name" dtach -c "$soc_name" -e ^^ sh -c "$SHELL"
  570. # echo "dt: Socket named $soc_name not exists and no command specified."
  571. # return 1
  572. else
  573. __MY_DTACH="$soc_name" dtach -c "$soc_name" -e ^^ "$@"
  574. fi
  575. }
  576. scr(){
  577. test -n "$1" && pf="${1}-"
  578. local _tformat="%Y%m%d-%H%M%S%z"
  579. local _file="${HOME}/${pf}`date +${_tformat}`.script"
  580. __MY_SCRIPT=${_file} script ${_file} "$@"
  581. }
  582. dtscr(){
  583. # dtscr <command ...>
  584. if test -z "$1"
  585. then
  586. echo "dtscr: usage: dtscr <command ...>"
  587. return 1
  588. fi
  589. local _cmdstr="`echo $@ | tr ' ' +`"
  590. local _tformat="%Y%m%d-%H%M%S%z"
  591. local _name="${pf}`date +${_tformat}`-${_cmdstr}"
  592. local _scr_file="${HOME}/${_name}.script"
  593. local _dt_dir="${TMP}/dtscr"
  594. install -d "$_dt_dir"
  595. dtach -n "${_dt_dir}/${_name}" script "${_scr_file_}" "$@"
  596. # echo $_name
  597. # echo $_file
  598. }
  599. mcrypt_stream(){
  600. test $# -eq 2 || return 1
  601. case $1 in
  602. en)
  603. mcrypt --key $2 | base64 ;;
  604. de)
  605. base64 -d | mcrypt -d --key $2 ;;
  606. esac
  607. }
  608. gpg_stream(){
  609. test $# -eq 2 || return 1
  610. case $1 in
  611. en)
  612. gpg --passphrase $2 -c --batch |base64 ;;
  613. de)
  614. base64 -d|gpg --passphrase $2 -d --batch ;;
  615. esac
  616. }
  617. dgpg(){
  618. if test "$1" = help || test -z "$2"
  619. then
  620. echo "dgpg: dgpg <en|de> <src-suffix> [<dst-suffix>]" 1>&2
  621. return
  622. fi
  623. local srcs="$2"
  624. local dsts="$3"
  625. test -z "$dsts" && dsts="${srcs}.out"
  626. local pw
  627. echo -n "dgpg pw: "
  628. read -s pw
  629. echo ""
  630. test -z "$pw" && return 1
  631. for f in *${srcs}
  632. do
  633. local d="$(basename "$f" "${srcs}")${dsts}"
  634. echo -n "Processing $f to $d..."
  635. if test -d "$f"
  636. then
  637. echo "`printf 'failed (%s is directory)' $f`"
  638. elif test -f "$d"
  639. then
  640. echo "`printf 'failed (%s is already exists)' $d`"
  641. elif <"$f" gpg_stream $1 $pw >"$d" 2>/dev/null
  642. then
  643. echo "done"
  644. else
  645. echo "failed"
  646. test -f "$d" && rm "$d"
  647. fi
  648. done
  649. }
  650. alias enst="gpg_stream en"
  651. alias dest="gpg_stream de"
  652. showinfo(){
  653. echo "Japanese letters are 表示可能"
  654. __safe_run diskinfo
  655. ! $isdarwin && test -n "${DISPLAY}" && {
  656. __safe_run xrandr | \grep --color=never ^Screen
  657. }
  658. $iswindows || __safe_run finger $USER
  659. LANG=C __safe_runc id
  660. __safe_run xset q
  661. }
  662. x(){
  663. if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  664. #mkdir -p ~/.var/log
  665. # nohup startx >~/.var/log/xorg.log 2>&1 &
  666. # exit
  667. exec startx
  668. else
  669. echo "X cant be started! Another X is already running?" 1>&2
  670. fi
  671. }
  672. bak(){
  673. for file in "$@"
  674. do
  675. cp -v ${file} ${file}.bak
  676. done
  677. }
  678. di(){
  679. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  680. then
  681. local diffcmd=colordiff
  682. else
  683. local diffcmd=diff
  684. fi
  685. ${diffcmd} -u "$@" | ${PAGER}
  686. }
  687. tb(){
  688. __datenum=`date +%Y%m%d-%H%M%S`
  689. __tb="$HOME/.var/tb/$__datenum"
  690. install -d "$__tb"
  691. for file in "$@"
  692. do
  693. mv -t "$__tb" "$file"
  694. done
  695. }
  696. mkcd(){
  697. if test -z "$1"
  698. then
  699. echo "mkcd: usage: mkcd <dir>"
  700. return 1
  701. elif test -d "$1"
  702. then
  703. echo "Dir \"$1\" already exists."
  704. else
  705. install -d "$1"
  706. echo "Dir \"$1\" created."
  707. fi
  708. cd "$1"
  709. }
  710. mkcdd(){
  711. # make and change date directory
  712. _d=`date +%Y%m%d-%H%M%S`
  713. mkcd "$_d"
  714. }
  715. if test -n "$TMUX" && null type reattach-to-user-namespace
  716. then
  717. alias pbpaste="reattach-to-user-namespace pbpaste"
  718. alias pbcopy="reattach-to-user-namespace pbcopy"
  719. fi
  720. catclip(){
  721. if $iswindows
  722. then
  723. cat /dev/clipboard | tr -d \\r
  724. elif $isdarwin
  725. then
  726. pbpaste
  727. else
  728. xclip -o -selection "clipboard"
  729. fi
  730. }
  731. setclip(){
  732. if test $# -eq 0
  733. then
  734. exec 3<&0
  735. else
  736. exec 3<<__EOF__
  737. `cat "$@"`
  738. __EOF__
  739. fi
  740. if $iswindows
  741. then
  742. 0<&3 sed -e 's/$/\r/' | tee /dev/clipboard
  743. elif $isdarwin
  744. then
  745. pbcopy 0<&3
  746. else
  747. 0<&3 xclip -i -f -selection "primary" | \
  748. xclip -i -f -selection "clipboard"
  749. fi
  750. exec 3<&-
  751. }
  752. open_file(){
  753. if $iscygwin
  754. then
  755. cygstart "$@"
  756. elif $ismsys
  757. then
  758. cmd.exe //c start "" "$@"
  759. elif $isdarwin
  760. then
  761. touch "$@"
  762. open "$@"
  763. elif $islinux
  764. then
  765. touch "$@"
  766. if null type pcmanfm; then
  767. LC_MESSAGES= pcmanfm "$@"
  768. else
  769. LC_MESSAGES= xdg-open "$@" &
  770. fi
  771. else
  772. cat "$@"
  773. fi
  774. }
  775. o(){
  776. if test $# -eq 0
  777. then
  778. open_file .
  779. else
  780. for f in "$@"
  781. do
  782. open_file "$(realpath "$f")"
  783. done
  784. fi
  785. }
  786. convmv_sjis2utf8_test(){
  787. convmv -r -f sjis -t utf8 *
  788. }
  789. convmv_sjis2utf8_notest(){
  790. convmv -r -f sjis -t utf8 * --notest
  791. }
  792. #################################################
  793. ## pastebin services
  794. ## https://wiki.archlinux.org/index.php/List_of_Applications/Internet#Pastebin_clients
  795. sprunge(){
  796. # http://sprunge.us
  797. if test -z "$1"
  798. then
  799. curl -F 'sprunge=<-' http://sprunge.us
  800. else
  801. curl http://sprunge.us/$1
  802. fi
  803. }
  804. dpaste(){
  805. # http://dpaste.de
  806. if test -z "$1"
  807. then
  808. curl -F 'content=<-' https://dpaste.de/api/
  809. echo
  810. else
  811. curl https://dpaste.de/$1/raw/
  812. fi
  813. }
  814. ##########################
  815. # Zsh specific preferences
  816. if $inzsh
  817. then
  818. bindkey -e
  819. # http://zsh.sourceforge.net/Guide/zshguide06.html#l147
  820. autoload compinit; compinit
  821. unsetopt auto_menu
  822. zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
  823. setopt bash_auto_list
  824. autoload colors; colors
  825. autoload -Uz promptinit
  826. promptinit
  827. prompt walters
  828. fi
  829. ######################################
  830. ## Prompt Settings
  831. __my_moc_state(){
  832. type mocp >/dev/null 2>&1 || return
  833. test "`mocp -Q %state 2>/dev/null`" = PLAY || return
  834. printf "$1" "`mocp -Q %title 2>/dev/null`"
  835. }
  836. __my_parse_svn_branch() {
  837. local LANG=C
  838. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  839. local svn_repository_root=$(svn info 2>/dev/null | \
  840. sed -ne 's#^Repository Root: ##p')
  841. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | \
  842. awk '{print $1}'
  843. }
  844. __my_svn_ps1(){
  845. if svn status >/dev/null 2>&1
  846. then
  847. local svn_branch=$(__my_parse_svn_branch)
  848. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  849. fi
  850. }
  851. __my_battery_status(){
  852. local dir=/sys/class/power_supply/BAT0
  853. if test -d $dir && test -r $dir/status && test -r $dir/charge_full && \
  854. test -r $dir/charge_now
  855. then
  856. local st=$(cat $dir/status)
  857. local full=$(cat $dir/charge_full)
  858. local now=$(cat $dir/charge_now)
  859. local rate=$(expr $now \* 100 / $full)
  860. printf "$1" "${st}:${rate}%"
  861. fi
  862. }
  863. alias bat='__my_battery_status %s\\n'
  864. ipaddress(){
  865. # ipaddress <fmt>
  866. type ip >/dev/null 2>&1 || return 1
  867. local ip=$(LANG=C ip addr show scope global | \
  868. \grep --color=never --only-matching 'inet [^ ]*' | cut -d " " -f 2)
  869. test -n "$ip" && printf $1 $ip
  870. }
  871. __my_ps1_str=""
  872. test -n "$__MY_SCRIPT" && __my_ps1_str="${__my_ps1_str}${__my_c5}SCR${__my_cdef} "
  873. test -n "$SSH_CONNECTION" && __my_ps1_str="${__my_ps1_str}${__my_c5}SSH${__my_cdef} "
  874. test -n "$__MY_DTACH" && __my_ps1_str="${__my_ps1_str}${__my_c5}DTACH${__my_cdef} "
  875. __my_ps1_scale(){
  876. if null type stty && ! $ismsys
  877. then
  878. echo "[LxC:`stty size | tr -d $'\n' | tr " " x`]"
  879. fi
  880. }
  881. __my_ps1_tmux(){
  882. null type tmux || return $last
  883. local tmuxc="$(tmux display -p '#S:#I:#W.#P' 2>/dev/null)"
  884. test -n "$TMUX" && echo "[TMUX:$tmuxc]"
  885. }
  886. __my_ps1_moc(){
  887. __my_moc_state "[MOC:%s]"
  888. }
  889. for f in /usr/share/git/git-prompt.sh \
  890. /opt/local/share/git-core/git-prompt.sh \
  891. /opt/local/share/doc/git-core/contrib/completion/git-prompt.sh
  892. do
  893. test -r "$f" && $inbash && . "$f" && break
  894. done
  895. GIT_PS1_SHOWDIRTYSTATE=t
  896. GIT_PS1_SHOWUPSTREAM=t
  897. __my_ps1_git(){
  898. null type __git_ps1 || return $last
  899. null git rev-parse --git-dir >/dev/null 2>&1 || return $last
  900. __git_ps1 "[GIT:$(__safe_run git config --get user.name):%s]"
  901. }
  902. __my_ps1_ipaddr(){
  903. ! $iswindows && ipaddress [Addr:%s]
  904. }
  905. __my_ps1_bttry(){
  906. local bst="${TMP}/batterystatus"
  907. if test -z "$DISPLAY" && ! $iswindows
  908. then
  909. test -f $bst && local bstr="$(cat $bst)"
  910. test -n "$bstr" && ! echo $bstr | grep 100 >/dev/null 2>&1 && \
  911. echo "[Battery:$bstr]"
  912. __my_battery_status %s >$bst &
  913. fi
  914. }
  915. __my_ps1_dirs(){
  916. dirs | wc -l
  917. }
  918. __my_ps1_jobs(){
  919. # __my_ps1_jobs <num>
  920. if test "$1" -ne 0
  921. then
  922. echo "[JOBS:$1] "
  923. fi
  924. }
  925. __my_alert_fail(){
  926. test $laststatus -eq 0 || \
  927. echo "[STATUS:${laststatus}] "
  928. }
  929. # About ansi escape sequences
  930. # http://archive.linux.or.jp/JF/JFdocs/Bash-Prompt-HOWTO-5.html
  931. # http://www.grapecity.com/japan/powernews/column/clang/047/page02.htm
  932. __attr_beg='\[\033['
  933. __attr_end='m\]'
  934. __color_default="${__attr_beg}0${__attr_end}"
  935. __color_black="${__attr_beg}0;30${__attr_end}"
  936. __color_red="${__attr_beg}0;31${__attr_end}"
  937. __color_green="${__attr_beg}0;32${__attr_end}"
  938. __color_brown="${__attr_beg}0;33${__attr_end}"
  939. __color_blue="${__attr_beg}0;34${__attr_end}"
  940. __color_purple="${__attr_beg}0;35${__attr_end}"
  941. __color_cyan="${__attr_beg}0;36${__attr_end}"
  942. __color_light_gray="${__attr_beg}0;37${__attr_end}"
  943. __color_dark_gray="${__attr_beg}1;30${__attr_end}"
  944. __color_light_red="${__attr_beg}1;31${__attr_end}"
  945. __color_light_green="${__attr_beg}1;32${__attr_end}"
  946. __color_yellow="${__attr_beg}1;33${__attr_end}"
  947. __color_light_blue="${__attr_beg}1;34${__attr_end}"
  948. __color_light_purple="${__attr_beg}1;35${__attr_end}"
  949. __color_light_cyan="${__attr_beg}1;36${__attr_end}"
  950. __color_white="${__attr_beg}1;37${__attr_end}"
  951. __color_bg_black="${__attr_beg}40${__attr_end}"
  952. __color_bg_red="${__attr_beg}41${__attr_end}"
  953. __color_bg_green="${__attr_beg}42${__attr_end}"
  954. __color_bg_brown="${__attr_beg}43${__attr_end}"
  955. __color_bg_blue="${__attr_beg}44${__attr_end}"
  956. __color_bg_purple="${__attr_beg}45${__attr_end}"
  957. __color_bg_cyan="${__attr_beg}46${__attr_end}"
  958. __color_bg_light_gray="${__attr_beg}47${__attr_end}"
  959. __attr_underline="${__attr_beg}4${__attr_end}"
  960. __attr_reverse="${__attr_beg}7${__attr_end}"
  961. __attr_bold="${__attr_beg}1${__attr_end}"
  962. # NOTE: tput is another easy way to set colors and background
  963. # For example, "$(tput setab 4)text$(tput sgr0)" print text with background
  964. # color blue.
  965. if test "$TERM" != dumb
  966. then
  967. __my_c1="$__attr_bold$__attr_underline" # color for PWD
  968. __my_c2="$__attr_bold$__attr_underline" # color for user and hostname
  969. # color for ::
  970. case "`hostname`" in
  971. arch-aspireone)
  972. __my_c4="$__color_light_blue"
  973. ;;
  974. darwin-mba.local)
  975. __my_c4="$__color_light_cyan"
  976. ;;
  977. newkiwi)
  978. __my_c4="$__color_light_purple"
  979. ;;
  980. *)
  981. __my_c4="$__color_light_green"
  982. ;;
  983. esac
  984. __my_c5="$__color_black$__color_bg_light_gray" # color for SCR
  985. __my_cdef="$__color_default"
  986. fi
  987. __my_ps1_info(){
  988. echo "$(__my_ps1_scale)$(__my_ps1_git)$(__my_ps1_bttry)$(__my_ps1_ipaddr)$(__my_ps1_moc)"
  989. }
  990. _ps1_bash="\
  991. ${__my_c4}:: ${__my_cdef}[${__my_c2}\u@\H${__my_cdef}:${__my_c1}\w/${__my_cdef}]\$(__my_ps1_info)\n\
  992. ${__my_c4}:: ${__my_cdef}\$(__my_ps1_jobs \j)${__my_ps1_str}\$(__my_alert_fail)\$ "
  993. $inbash && PS1=$_ps1_bash
  994. #$inzsh && PS1="$_ps1_zsh"
  995. __my_set_header_line(){
  996. # save current position
  997. printf "\033[s"
  998. printf "\033[0;0H"
  999. printf "\033[K"
  1000. printf "\033[7m"
  1001. printf "$1"
  1002. printf "\033[0m"
  1003. # restore saved position
  1004. printf "\033[u"
  1005. }
  1006. __my_set_screen_title(){
  1007. if test -n "$TMUX" && test -z "$INSIDE_EMACS"
  1008. then
  1009. echo -ne "\033k$1\033\\"
  1010. fi
  1011. }
  1012. __my_set_title(){
  1013. case $TERM in
  1014. (rxvt*|xterm*|aterm|screen*)
  1015. test -t 1 &&
  1016. test -n "$DISPLAY" &&
  1017. test -z "$EMACS" &&
  1018. echo -n -e "\033]0;$1\007"
  1019. ;;
  1020. esac
  1021. }
  1022. PROMPT_COMMAND="__my_set_title \${USER}@\${HOSTNAME}\:\${PWD};
  1023. __my_set_screen_title \$(basename \"\$PWD\")/"
  1024. PROMPT_COMMAND="laststatus=\$?;$PROMPT_COMMAND"
  1025. laststatus=0