You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
13 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. #!/bin/bash
  2. # 外部ファイルの読み込み
  3. # test -r ~/filepath && . ~/filepath
  4. # ln SRC DST
  5. ##########################
  6. # system type
  7. # $OSTYPEとか使えるのかな
  8. if uname | grep -E "^MINGW32" >/dev/null 2>&1
  9. then
  10. alias ismsys=true
  11. else
  12. alias ismsys=false
  13. fi
  14. if uname | grep -E "^CYGWIN" >/dev/null 2>&1
  15. then
  16. alias iscygwin=true
  17. else
  18. alias iscygwin=false
  19. fi
  20. alias iswindows="iscygwin || ismsys"
  21. if uname | grep -E 'Darwin' >/dev/null 2>&1
  22. then
  23. alias isdarwin=true
  24. else
  25. alias isdarwin=false
  26. fi
  27. ##########################################
  28. safe-cmd(){
  29. type $1 >/dev/null 2>&1 && "$@"
  30. }
  31. replace-cmd(){
  32. type $1 1>/dev/null || alias $1=:
  33. }
  34. test -r /etc/bashrc && . /etc/bashrc
  35. export PS1="\$(prompt_function)\$ "
  36. # PROMPT_COMMAND=prompt_function
  37. if iswindows
  38. then
  39. export PAGER="tr -d '\r' | less"
  40. else
  41. export PAGER="less"
  42. fi
  43. export EDITOR="vi"
  44. export VISUAL="$EDITOR"
  45. export LESS="-iRMX"
  46. # export LC_MESSAGES="C"
  47. # export LANG=ja_JP.UTF-8
  48. # export CDPATH=".:~" # 使い方がよく分からない
  49. export GIT_PAGER="$PAGER"
  50. export GIT_EDITOR="$EDITOR"
  51. alias ls="ls -CFG $(test "$TERM" == dumb || echo --color=auto) --time-style=long-iso"
  52. alias ll="ls -l"
  53. alias la="ls -A"
  54. alias lla="ls -Al"
  55. # alias less=""
  56. alias vl=/usr/share/vim/vimcurrent/macros/less.sh
  57. alias em="emacs -nw"
  58. alias apt-get="sudo apt-get"
  59. alias aptin="apt-get install"
  60. alias aptsearch="apt-cache search"
  61. alias aptshow="apt-cache show"
  62. alias ut="ssh t110414@un001.ecc.u-tokyo.ac.jp"
  63. alias rand="echo \$RANDOM"
  64. alias xunp="file-roller -h"
  65. alias pacome="sudo \paco -D"
  66. alias destroy="rm -rf"
  67. alias psall="ps auxww"
  68. alias g=git
  69. alias q=exit
  70. alias pcalc="python -i -c 'from math import *' "
  71. # alias diff="$(type colordiff >/dev/null 2>&1 && test $TERM != dumb && echo color)diff -u"
  72. # type trash >/dev/null 2>&1 && alias rm=trash
  73. export __MYGITBAREREP="${HOME}/dbx/.git-bare"
  74. git-make-bare-rep(){
  75. test $# -eq 0 && {
  76. echo "specify repository name." 1>&2
  77. return 1
  78. }
  79. dir="${__MYGITBAREREP}/$1.git"
  80. if test -d "$dir"
  81. then
  82. echo "dir $dir already exist!" 1>&2
  83. else
  84. mkdir -p "$dir" &&
  85. pushd "$dir" &&
  86. git init --bare --shared=all
  87. popd
  88. fi
  89. }
  90. git-add-bare-rep(){
  91. test $# -ne 2 && {
  92. echo "specify repository name and shortname." 1>&2
  93. return 1
  94. }
  95. dir="${__MYGITBAREREP}/$2.git"
  96. # git-make-bare-rep $2 &&
  97. # git remote add $1 "$dir"
  98. # git remote -v
  99. if test -d "$dir"
  100. then
  101. git remote add $1 "$dir"
  102. git remote -v
  103. else
  104. echo "dir $dir does not exist!" 1>&2
  105. fi
  106. }
  107. bak(){
  108. for file in "$@"
  109. do
  110. cp ${file} ${file}.bak
  111. done
  112. }
  113. di(){
  114. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  115. then
  116. local diffcmd=colordiff
  117. else
  118. local diffcmd=diff
  119. fi
  120. ${diffcmd} -u "$@" | ${PAGER}
  121. }
  122. memo(){
  123. __MYMEMO="# $*\n"
  124. }
  125. rmmemo(){
  126. __MYMEMO=""
  127. }
  128. throw-away(){
  129. mkdir -p ~/bu/tb
  130. for file in "$@"
  131. do
  132. mv $file ~/bu/tb
  133. done
  134. }
  135. mkcd(){
  136. mkdir -p $1
  137. cd $1
  138. }
  139. catclip(){
  140. if iswindows
  141. then
  142. cat /dev/clipboard | tr -d \\r
  143. else
  144. xclip -o -selection "clipboard"
  145. fi
  146. }
  147. setclip(){
  148. if iswindows
  149. then
  150. if test $# -eq 0
  151. then
  152. sed -e 's/$/\r/' | tee /dev/clipboard
  153. else
  154. cat "$@" | sed -e 's/$/\r/' | tee /dev/clipboard
  155. fi
  156. else
  157. if test $# -eq 0
  158. then
  159. xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  160. else
  161. cat "$@" | xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  162. fi
  163. fi
  164. }
  165. p(){
  166. "$@" | $PAGER
  167. }
  168. c(){
  169. "$@" | cat
  170. }
  171. o(){
  172. if [ $# -eq 0 ]
  173. then
  174. local f=.
  175. else
  176. local f="$1"
  177. fi
  178. if iswindows
  179. then
  180. cmd.exe //c start "" "$f"
  181. elif isdarwin
  182. then
  183. open "$f"
  184. else
  185. xdg-open "$f"
  186. fi
  187. }
  188. convmv-sjis2utf8-test(){
  189. convmv -r -f sjis -t utf8 *
  190. }
  191. convmv-sjis2utf8-notest(){
  192. convmv -r -f sjis -t utf8 * --notest
  193. }
  194. dl-my-init-files(){
  195. for file in .bashrc .vimrc .emacs
  196. do
  197. local flag=0
  198. if test -f ~/${file}.new
  199. then
  200. mv ~/${file}.new ~/${file}.old
  201. echo "${file}.new already exist. Rename it to ${file}.old."
  202. flag=1
  203. fi
  204. wget https://dl.dropbox.com/u/1751156/${file} -O ~/${file}.new
  205. local wgetreturn=$?
  206. if test ${flag} -eq 1 -a ${wgetreturn} -eq 0
  207. then
  208. rm ~/${file}.old
  209. echo "${file}.old deleted."
  210. fi
  211. done
  212. }
  213. port-autosync(){
  214. port selfupdate && port sync && port upgrade installed
  215. }
  216. _mygitconfig(){
  217. git config --global user.name '10sr'
  218. git config --global user.email '8slashes+git@gmail.com'
  219. git config --global core.autocrlf false
  220. git config --global color.ui auto
  221. git config --global status.relativePaths false
  222. git config --global status.showUntrackedFiles normal
  223. git config --global alias.graph "log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"
  224. git config --global alias.st "status -s"
  225. git config --global alias.b "branch"
  226. git config --global alias.ci "commit --verbose"
  227. git config --global alias.co "checkout"
  228. git config --global alias.cim "commit --verbose -m"
  229. git config --global alias.di "diff"
  230. git config --global alias.me "merge --no-ff --stat -v"
  231. git config --global alias.ls "ls-files"
  232. # git config --global alias.my-ls "ls-files | xargs ls"
  233. # git config --global alias.ll "!git ls-files | xargs ls -l -CFG --color=auto --time-style=long-iso"
  234. git config --global alias.addi "add -i"
  235. if iswindows; then
  236. git config --global core.fileMode false
  237. fi
  238. }
  239. __my_parse_svn_branch() {
  240. local LANG=C
  241. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  242. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  243. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  244. }
  245. __my_svn_ps1(){
  246. local svn_branch=$(__my_parse_svn_branch)
  247. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  248. }
  249. replace-cmd date
  250. replace-cmd __my_svn_ps1
  251. prompt_function(){ # used by PS1
  252. local lastreturn=$?
  253. if test "${TERM}" == dumb
  254. then
  255. local c1=
  256. local c2=
  257. local c3=
  258. local cdef=
  259. else
  260. local c1="\e[33m"
  261. local c2="\e[36m"
  262. local c3="\e[37m"
  263. local cdef="\e[0m"
  264. fi
  265. if iswindows
  266. then
  267. local pwd=$PWD
  268. local oldpwd=$OLDPWD
  269. local jobnum=
  270. if git branch >/dev/null 2>&1
  271. then
  272. local git="[GIT]"
  273. else
  274. local git=
  275. fi
  276. local date=$(/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%')
  277. :
  278. else
  279. local pwd=$(echo "${PWD}/" | sed -e "s#${HOME}#~#")
  280. local oldpwd=$(echo "${OLDPWD}/" | sed -e "s#${HOME}#~#")
  281. local jobnum=$(jobs | wc -l)
  282. local git=$(safe-cmd __git_ps1 [GIT:%s])
  283. local date=$(LANG=C safe-cmd date +"%a, %d %b %Y %T %z")
  284. fi
  285. local svn=$(type svn >/dev/null 2>&1 && safe-cmd __my_svn_ps1 [SVN:%s])
  286. printf "${_MEMO}"
  287. printf " [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}${svn}\n"
  288. printf "${c2}${USER}@${HOSTNAME}${cdef} ${date} ${BASH} ${BASH_VERSION}\n"
  289. printf "shlv:${SHLVL} jobs:${jobnum} last:${lastreturn} "
  290. }
  291. # type date >/dev/null 2>&1 || alias date=":" # "cmd /c echo %time%"
  292. if [ "${EMACS}" = "t" ]; then # emacs shell用
  293. : export PS1="\u@\H \d \t \w\nemacs shell\$ "
  294. elif echo "$EMACS" | grep term >/dev/null 2>&1; then # emacs term用
  295. echo "emacs term"
  296. fi
  297. #Change ANSI Colors
  298. _chengecolors(){
  299. echo -e \
  300. "\e]P0000000" \
  301. "\e]P1cd0000" \
  302. "\e]P200cd00" \
  303. "\e]P3cdcd00" \
  304. "\e]P41e90ff" \
  305. "\e]P5cd00cd" \
  306. "\e]P600cdcd" \
  307. "\e]P7353535" \
  308. "\e]P8666666" \
  309. "\e]P9ff9999" \
  310. "\e]Pa99ff99" \
  311. "\e]Pbffff99" \
  312. "\e]Pc9999ff" \
  313. "\e]Pdff99ff" \
  314. "\e]Pe99ffff" \
  315. "\e]Pfffffff"
  316. }
  317. # printf "\e]P7353535" \
  318. _echocolors(){
  319. echo -e \
  320. "\e[30mBlack\n" \
  321. "\e[31mRed\n" \
  322. "\e[32mGreen\n" \
  323. "\e[33mYellow\n" \
  324. "\e[34mBlue\n" \
  325. "\e[35mMagenta\n" \
  326. "\e[36mCyan\n" \
  327. "\e[37mWhite\n" \
  328. "\e[30;1mBright Black\n" \
  329. "\e[31;1mBright Red\n" \
  330. "\e[32;1mBright Green\n" \
  331. "\e[33;1mBright Yellow\n" \
  332. "\e[34;1mBright Blue\n" \
  333. "\e[35;1mBright Magenta\n" \
  334. "\e[36;1mBright Cyan\n" \
  335. "\e[37;1mBright White\n" \
  336. "\e[0m"
  337. }
  338. safe-cmd stty stop undef # unbind C-s to stop displaying output
  339. #########################
  340. # for windose
  341. winln(){
  342. if test $# -eq 0
  343. then
  344. {
  345. echo "usage: winln TARGET LINK_NAME"
  346. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  347. echo "About other features run 'junction'."
  348. } 1>&2
  349. return 1
  350. else
  351. junction "$2" "$1"
  352. fi
  353. }
  354. ########################
  355. if iscygwin; then
  356. alias cygsu="cygstart /cygwinsetup.exe"
  357. alias emacs="CYGWIN=tty emacs -nw"
  358. echo "cygwin bash"
  359. fi
  360. if iswindows; then
  361. # export TMP=/tmp
  362. # export TEMP=/tmp
  363. # export PS1=" \[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ "
  364. # export PS1=" [\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ "
  365. alias ls="ls -CFG $(test "$TERM" == dumb || echo --color=auto)"
  366. export USER=$USERNAME
  367. fi
  368. #######################
  369. echo "Japanese letters are 表示可能"
  370. safe-cmd diskinfo
  371. test -n "${DESKTOP_SESSION}" && type xrandr >/dev/null 2>&1 && {
  372. xrandr | grep --color=never ^Screen
  373. }
  374. iswindows || safe-cmd finger $USER
  375. LANG=C safe-cmd id