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.
 
 
 
 
 
 

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