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.
 
 
 
 
 
 

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