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.
 
 
 
 
 
 

252 lines
6.3 KiB

  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="-iRM"
  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. safe-exec(){
  41. type $1 >/dev/null 2>&1 && "$@"
  42. }
  43. o(){
  44. if [ $# -eq 0 ]; then
  45. local f=.
  46. else
  47. local f="$1"
  48. fi
  49. if iswindows; then
  50. cmd.exe //c start "" "$f"
  51. elif isdarwin; then
  52. open "$f"
  53. else
  54. xdg-open "$f"
  55. fi
  56. }
  57. sgcc(){
  58. if iswindows; then
  59. gcc -o win.$1.exe $1
  60. else
  61. gcc -o $(uname).$1.out $1
  62. fi
  63. }
  64. sggcc(){
  65. gcc -g -o $(uname).$1.out $1
  66. }
  67. slmggcc(){
  68. gcc -g -lm -o $(uname).$1.out $1
  69. }
  70. convmv-sjis2utf8-test(){
  71. convmv -r -f sjis -t utf8 *
  72. }
  73. convmv-sjis2utf8-notest(){
  74. convmv -r -f sjis -t utf8 * --notest
  75. }
  76. dl-my-init-files(){
  77. for file in .bashrc .vimrc .emacs
  78. do
  79. local flag=0
  80. if test -f ~/${file}.new
  81. then
  82. mv ~/${file}.new ~/${file}.old
  83. echo "${file}.new already exist. Rename it to ${file}.old."
  84. flag=1
  85. fi
  86. wget https://dl.dropbox.com/u/1751156/${file} -O ~/${file}.new
  87. local wgetreturn=$?
  88. if test ${flag} -eq 1 -a ${wgetreturn} -eq 0
  89. then
  90. rm ~/${file}.old
  91. echo "${file}.old deleted."
  92. fi
  93. done
  94. }
  95. port-autosync(){
  96. port selfupdate && port sync && port upgrade installed
  97. }
  98. _mygitconfig(){
  99. # export GISTY_DIR="$HOME/dev/gists"
  100. git config --global user.name "10sr"
  101. git config --global user.email sr10@users.sourceforge.jp
  102. git config --global core.autocrlf false
  103. git config --global color.ui auto
  104. git config --global alias.log-all "log --graph --all --color --pretty='%x09%h %cn%x09%s %Cred%d%Creset'"
  105. git config --global alias.log-all2 "log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short"
  106. git config --global alias.log-all3 "log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"
  107. git config --global alias.cmm "commit -m"
  108. # git config --global github.token **
  109. }
  110. prompt_function(){ # used by PS1
  111. local lastreturn=$?
  112. if test "${TERM}" == dumb
  113. then
  114. local c1=""
  115. local c2=""
  116. local cdef=""
  117. else
  118. local c1="\e[33m"
  119. local c2="\e[32m"
  120. local cdef="\e[0m"
  121. fi
  122. local pwd=$(echo "${PWD}/" | sed -e "s:${HOME}:~:")
  123. local date=$(LANG=C safe-exec date +"%a, %d %b %Y %T %z")
  124. local jobnum=$(jobs | wc -l)
  125. local git=$(safe-exec __git_ps1 [GIT:%s])
  126. printf " [${c1}${pwd}${cdef}]${git}\n"
  127. printf "${c2}${USER}@${HOSTNAME}${cdef} ${date} ${BASH} ${BASH_VERSION}\n"
  128. printf "jobs:${jobnum} last:${lastreturn} "
  129. }
  130. # type date >/dev/null 2>&1 || alias date=":" # "cmd /c echo %time%"
  131. if [ "${EMACS}" = "t" ]; then # emacs shell用
  132. export PS1="\u@\H \d \t \w\nemacs shell\$ "
  133. elif echo "$EMACS" | grep term >/dev/null 2>&1; then # emacs term用
  134. echo "emacs term"
  135. fi
  136. # #Change ANSI Colors
  137. # if [ $TERM = "xterm" ]
  138. # then
  139. # echo -e \
  140. # "\e]P0000000" \
  141. # "\e]P1cd0000" \
  142. # "\e]P200cd00" \
  143. # "\e]P3cdcd00" \
  144. # "\e]P41e90ff" \
  145. # "\e]P5cd00cd" \
  146. # "\e]P600cdcd" \
  147. # "\e]P7353535" \
  148. # "\e]P8666666" \
  149. # "\e]P9ff9999" \
  150. # "\e]Pa99ff99" \
  151. # "\e]Pbffff99" \
  152. # "\e]Pc9999ff" \
  153. # "\e]Pdff99ff" \
  154. # "\e]Pe99ffff" \
  155. # "\e]Pfffffff"
  156. # fi
  157. # printf "\e]P7353535" \
  158. _echocolors(){
  159. echo -e \
  160. "\e[30mBlack\n" \
  161. "\e[31mRed\n" \
  162. "\e[32mGreen\n" \
  163. "\e[33mYellow\n" \
  164. "\e[34mBlue\n" \
  165. "\e[35mMagenta\n" \
  166. "\e[36mCyan\n" \
  167. "\e[37mWhite\n" \
  168. "\e[30;1mBright Black\n" \
  169. "\e[31;1mBright Red\n" \
  170. "\e[32;1mBright Green\n" \
  171. "\e[33;1mBright Yellow\n" \
  172. "\e[34;1mBright Blue\n" \
  173. "\e[35;1mBright Magenta\n" \
  174. "\e[36;1mBright Cyan\n" \
  175. "\e[37;1mBright White\n" \
  176. "\e[0m"
  177. }
  178. ##########################
  179. # system type
  180. # $OSTYPEとか使えるのかな
  181. iswindows(){
  182. uname | grep -iE 'windows|MINGW' >/dev/null 2>&1
  183. }
  184. ismsys(){}
  185. iscygwin(){}
  186. isdarwin(){
  187. uname | grep -E 'Darwin' >/dev/null 2>&1
  188. }
  189. #########################
  190. # for windose
  191. winln(){
  192. if [ $# -eq 0 ]; then
  193. echo "usage: winln TARGET LINK_NAME"
  194. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  195. echo "About other features run 'junction'."
  196. return 1
  197. else
  198. junction "$2" "$1"
  199. fi
  200. }
  201. ########################
  202. if [ "${CYGWIN}" = "t" ]; then # cygwin判定ってどうやるんだろ 多分unameとか使う
  203. # for cygwin
  204. export TMP=/tmp
  205. export TEMP=/tmp
  206. catclip(){
  207. cat /dev/clipboard | tr -d \\r
  208. }
  209. setclip(){
  210. if [ $# -eq 0 ]; then # 引数があるかを判定
  211. sed -e 's/$/\r/' | tee /dev/clipboard
  212. else
  213. cat $1 | sed -e 's/$/\r/' | tee /dev/clipboard
  214. fi
  215. }
  216. # alias setclip="tee /dev/clipboard"
  217. # alias catclip="cat /dev/clipboard | tr -d \\r"
  218. alias cygsu="cygstart /cygwinsetup.exe"
  219. alias emacs="CYGWIN=tty emacs"
  220. echo "cygwin bash"
  221. fi
  222. echo "Japanese letters are 表示可能"
  223. #######################
  224. safe-exec diskinfo
  225. finger $USER
  226. LANG=C id