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