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.

.bashrc 6.8 KiB

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