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