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.
 
 
 
 
 
 

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