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.

.bashrc 5.6 KiB

13 years ago
13 years ago
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #!/bin/bash
  2. # 外部ファイルの読み込み
  3. # test -r ~/filepath && . ~/filepath
  4. # ln SRC DST
  5. ##########################################
  6. test -r /etc/bashrc && . /etc/bashrc
  7. # export PS1="\[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ "
  8. # export PS1="[\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ "
  9. export PS1="\$(prompt_function)\$ "
  10. # PROMPT_COMMAND=prompt_function
  11. export PAGER="less"
  12. export EDITOR="vim"
  13. export VISUAL=$EDITOR
  14. export LESS="-M"
  15. # export LC_MESSAGES="C"
  16. # export LANG=ja_JP.UTF-8
  17. # export CDPATH=".:~" # 使い方がよく分からない
  18. export GIT_PAGER=$PAGER
  19. export GIT_EDITOR=$EDITOR
  20. mkunfddir(){ # create dir if unfound. ?
  21. test -e "$1" || mkdir "$1"
  22. }
  23. if test "${TERM}" == dumb
  24. then
  25. alias ls="ls -CFG --time-style=long-iso"
  26. else
  27. alias ls="ls -CFG --color=auto --time-style=long-iso"
  28. fi
  29. alias ll="ls -l"
  30. alias la="ls -A"
  31. alias lla="ls -Al"
  32. alias vl=/usr/share/vim/vimcurrent/macros/less.sh
  33. alias emacs="emacs -nw"
  34. alias aptin="sudo apt-get install"
  35. alias ut="slogin t110414@un001.ecc.u-tokyo.ac.jp"
  36. alias rand="echo \$RANDOM"
  37. alias xunp="file-roller -h"
  38. alias pacome="sudo \paco -D"
  39. # type trash >/dev/null 2>&1 && alias rm=trash
  40. o(){
  41. if [ $# -eq 0 ]; then
  42. local f=.
  43. else
  44. local f="$1"
  45. fi
  46. if iswindows; then
  47. cmd.exe //c start "" "$f"
  48. elif isdarwin; then
  49. open "$f"
  50. else
  51. xdg-open "$f"
  52. fi
  53. }
  54. sgcc(){
  55. if iswindows; then
  56. gcc -o win.$1.exe $1
  57. else
  58. gcc -o $(uname).$1.out $1
  59. fi
  60. }
  61. sggcc(){
  62. gcc -g -o $(uname).$1.out $1
  63. }
  64. slmggcc(){
  65. gcc -g -lm -o $(uname).$1.out $1
  66. }
  67. convmv-sjis2utf8-test(){
  68. convmv -r -f sjis -t utf8 *
  69. }
  70. convmv-sjis2utf8-notest(){
  71. convmv -r -f sjis -t utf8 * --notest
  72. }
  73. dl-my-init-files(){
  74. for file in .bashrc .vimrc .emacs
  75. do
  76. local flag=0
  77. if test -f ~/${file}.new
  78. then
  79. mv ~/${file}.new ~/${file}.old
  80. echo "${file}.new already exist. Rename it to ${file}.old."
  81. flag=1
  82. fi
  83. wget https://dl.dropbox.com/u/1751156/${file} -O ~/${file}.new
  84. local wgetreturn=$?
  85. if test ${flag} -eq 1 -a ${wgetreturn} -eq 0
  86. then
  87. rm ~/${file}.old
  88. echo "${file}.old deleted."
  89. fi
  90. done
  91. }
  92. port-auto(){
  93. port selfupdate && port sync && port upgrade installed
  94. }
  95. prompt_function(){ # used by PS1
  96. local lastreturn=$?
  97. if test "${TERM}" == dumb
  98. then
  99. local c1=""
  100. local c2=""
  101. local cdef=""
  102. else
  103. local c1="\e[33m"
  104. local c2="\e[32m"
  105. local cdef="\e[0m"
  106. fi
  107. local pwd=$(echo "${PWD}/" | sed -e "s:${HOME}:~:")
  108. local date=$(LANG=C date +"%a, %d %b %Y %T %z")
  109. local jobnum=$(jobs | wc -l)
  110. type __git_ps1 >/dev/null 2>&1 && local gitb=$(__git_ps1 GIT:%s)
  111. type git >/dev/null 2>&1 && local git="[${gitb}]"
  112. printf " [${c1}${pwd}${cdef}]${git}\n"
  113. printf "${c2}${USERNAME}@${HOSTNAME}${cdef} ${date} ${BASH} ${BASH_VERSION}\n"
  114. printf "jobs:${jobnum} last:${lastreturn} "
  115. }
  116. # type date >/dev/null 2>&1 || alias date=":" # "cmd /c echo %time%"
  117. if [ "${EMACS}" = "t" ]; then # emacs shell用
  118. export PS1="\u@\H \d \t \w\nemacs shell\$ "
  119. elif echo "$EMACS" | grep term >/dev/null 2>&1; then # emacs term用
  120. echo "emacs term"
  121. fi
  122. # #Change ANSI Colors
  123. # if [ $TERM = "xterm" ]
  124. # then
  125. # echo -e \
  126. # "\e]P0000000" \
  127. # "\e]P1cd0000" \
  128. # "\e]P200cd00" \
  129. # "\e]P3cdcd00" \
  130. # "\e]P41e90ff" \
  131. # "\e]P5cd00cd" \
  132. # "\e]P600cdcd" \
  133. # "\e]P7353535" \
  134. # "\e]P8666666" \
  135. # "\e]P9ff9999" \
  136. # "\e]Pa99ff99" \
  137. # "\e]Pbffff99" \
  138. # "\e]Pc9999ff" \
  139. # "\e]Pdff99ff" \
  140. # "\e]Pe99ffff" \
  141. # "\e]Pfffffff"
  142. # fi
  143. # printf "\e]P7353535" \
  144. _echocolors(){
  145. echo -e \
  146. "\e[30mBlack\n" \
  147. "\e[31mRed\n" \
  148. "\e[32mGreen\n" \
  149. "\e[33mYellow\n" \
  150. "\e[34mBlue\n" \
  151. "\e[35mMagenta\n" \
  152. "\e[36mCyan\n" \
  153. "\e[37mWhite\n" \
  154. "\e[30;1mBright Black\n" \
  155. "\e[31;1mBright Red\n" \
  156. "\e[32;1mBright Green\n" \
  157. "\e[33;1mBright Yellow\n" \
  158. "\e[34;1mBright Blue\n" \
  159. "\e[35;1mBright Magenta\n" \
  160. "\e[36;1mBright Cyan\n" \
  161. "\e[37;1mBright White\n" \
  162. "\e[0m"
  163. }
  164. ##########################
  165. # system type
  166. # $OSTYPEとか使えるのかな
  167. iswindows(){
  168. uname | grep -iE 'windows|MINGW' >/dev/null 2>&1
  169. }
  170. isdarwin(){
  171. uname | grep -E 'Darwin' >/dev/null 2>&1
  172. }
  173. #########################
  174. # for windose
  175. winln(){
  176. if [ $# -eq 0 ]; then
  177. echo "usage: winln TARGET LINK_NAME"
  178. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  179. echo "About other features run 'junction'."
  180. return 1
  181. else
  182. junction "$2" "$1"
  183. fi
  184. }
  185. ########################
  186. if [ "${CYGWIN}" = "t" ]; then # cygwin判定ってどうやるんだろ 多分unameとか使う
  187. # for cygwin
  188. export TMP=/tmp
  189. export TEMP=/tmp
  190. catclip(){
  191. cat /dev/clipboard | tr -d \\r
  192. }
  193. setclip(){
  194. if [ $# -eq 0 ]; then # 引数があるかを判定
  195. sed -e 's/$/\r/' | tee /dev/clipboard
  196. else
  197. cat $1 | sed -e 's/$/\r/' | tee /dev/clipboard
  198. fi
  199. }
  200. # alias setclip="tee /dev/clipboard"
  201. # alias catclip="cat /dev/clipboard | tr -d \\r"
  202. alias cygsu="cygstart /cygwinsetup.exe"
  203. alias emacs="CYGWIN=tty emacs"
  204. echo "cygwin bash"
  205. fi
  206. echo "Japanese letters are 表示可能"
  207. #######################
  208. type diskinfo >/dev/null 2>&1 && diskinfo
  209. finger $USER
  210. LANG=C id