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.
 
 
 
 
 
 

284 lines
7.0 KiB

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