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.
 
 
 
 
 
 

261 lines
6.5 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-cmd(){
  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 status.relativePaths false
  105. git config --global status.showUntrackedFiles no
  106. git config --global alias.log-all "log --graph --all --color --pretty='%x09%h %cn%x09%s %Cred%d%Creset'"
  107. git config --global alias.log-all2 "log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short"
  108. git config --global alias.graph "log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"
  109. git config --global alias.cmm "commit -m"
  110. git config --global alias.b "branch"
  111. git config --global alias.cm "commit --verbose"
  112. # git config --global github.token **
  113. }
  114. prompt_function(){ # used by PS1
  115. local lastreturn=$?
  116. if test "${TERM}" == dumb
  117. then
  118. local c1=""
  119. local c2=""
  120. local cdef=""
  121. else
  122. local c1="\e[33m"
  123. local c2="\e[32m"
  124. local cdef="\e[0m"
  125. fi
  126. local pwd=$(echo "${PWD}/" | sed -e "s:${HOME}:~:")
  127. local date=$(LANG=C safe-cmd date +"%a, %d %b %Y %T %z")
  128. local jobnum=$(jobs | wc -l)
  129. local git=$(safe-cmd __git_ps1 [GIT:%s])
  130. printf " [${c1}${pwd}${cdef}]${git}\n"
  131. printf "${c2}${USER}@${HOSTNAME}${cdef} ${date} ${BASH} ${BASH_VERSION}\n"
  132. printf "jobs:${jobnum} last:${lastreturn} "
  133. }
  134. # type date >/dev/null 2>&1 || alias date=":" # "cmd /c echo %time%"
  135. if [ "${EMACS}" = "t" ]; then # emacs shell用
  136. export PS1="\u@\H \d \t \w\nemacs shell\$ "
  137. elif echo "$EMACS" | grep term >/dev/null 2>&1; then # emacs term用
  138. echo "emacs term"
  139. fi
  140. # #Change ANSI Colors
  141. # if [ $TERM = "xterm" ]
  142. # then
  143. # echo -e \
  144. # "\e]P0000000" \
  145. # "\e]P1cd0000" \
  146. # "\e]P200cd00" \
  147. # "\e]P3cdcd00" \
  148. # "\e]P41e90ff" \
  149. # "\e]P5cd00cd" \
  150. # "\e]P600cdcd" \
  151. # "\e]P7353535" \
  152. # "\e]P8666666" \
  153. # "\e]P9ff9999" \
  154. # "\e]Pa99ff99" \
  155. # "\e]Pbffff99" \
  156. # "\e]Pc9999ff" \
  157. # "\e]Pdff99ff" \
  158. # "\e]Pe99ffff" \
  159. # "\e]Pfffffff"
  160. # fi
  161. # printf "\e]P7353535" \
  162. _echocolors(){
  163. echo -e \
  164. "\e[30mBlack\n" \
  165. "\e[31mRed\n" \
  166. "\e[32mGreen\n" \
  167. "\e[33mYellow\n" \
  168. "\e[34mBlue\n" \
  169. "\e[35mMagenta\n" \
  170. "\e[36mCyan\n" \
  171. "\e[37mWhite\n" \
  172. "\e[30;1mBright Black\n" \
  173. "\e[31;1mBright Red\n" \
  174. "\e[32;1mBright Green\n" \
  175. "\e[33;1mBright Yellow\n" \
  176. "\e[34;1mBright Blue\n" \
  177. "\e[35;1mBright Magenta\n" \
  178. "\e[36;1mBright Cyan\n" \
  179. "\e[37;1mBright White\n" \
  180. "\e[0m"
  181. }
  182. ##########################
  183. # system type
  184. # $OSTYPEとか使えるのかな
  185. iswindows(){
  186. uname | grep -iE 'windows|MINGW' >/dev/null 2>&1
  187. }
  188. ismsys(){
  189. :
  190. }
  191. iscygwin(){
  192. :
  193. }
  194. isdarwin(){
  195. uname | grep -E 'Darwin' >/dev/null 2>&1
  196. }
  197. #########################
  198. # for windose
  199. winln(){
  200. if [ $# -eq 0 ]; then
  201. echo "usage: winln TARGET LINK_NAME"
  202. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  203. echo "About other features run 'junction'."
  204. return 1
  205. else
  206. junction "$2" "$1"
  207. fi
  208. }
  209. ########################
  210. if [ "${CYGWIN}" = "t" ]; then # cygwin判定ってどうやるんだろ 多分unameとか使う
  211. # for cygwin
  212. export TMP=/tmp
  213. export TEMP=/tmp
  214. catclip(){
  215. cat /dev/clipboard | tr -d \\r
  216. }
  217. setclip(){
  218. if [ $# -eq 0 ]; then # 引数があるかを判定
  219. sed -e 's/$/\r/' | tee /dev/clipboard
  220. else
  221. cat $1 | sed -e 's/$/\r/' | tee /dev/clipboard
  222. fi
  223. }
  224. # alias setclip="tee /dev/clipboard"
  225. # alias catclip="cat /dev/clipboard | tr -d \\r"
  226. alias cygsu="cygstart /cygwinsetup.exe"
  227. alias emacs="CYGWIN=tty emacs"
  228. echo "cygwin bash"
  229. fi
  230. echo "Japanese letters are 表示可能"
  231. #######################
  232. safe-cmd diskinfo
  233. safe-cmd finger $USER
  234. LANG=C safe-cmd id