選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

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