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 9.4 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
12 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
13 years ago
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. #!/bin/bash
  2. # 外部ファイルの読み込み
  3. # test -r ~/filepath && . ~/filepath
  4. # ln SRC DST
  5. ##########################
  6. # system type
  7. # $OSTYPEとか使えるのかな
  8. if uname | grep -E "^MINGW32" >/dev/null 2>&1
  9. then
  10. alias ismsys=true
  11. else
  12. alias ismsys=false
  13. fi
  14. if uname | grep -E "^CYGWIN" >/dev/null 2>&1
  15. then
  16. alias iscygwin=true
  17. else
  18. alias iscygwin=false
  19. fi
  20. alias iswindows="iscygwin || ismsys"
  21. if uname | grep -E 'Darwin' >/dev/null 2>&1
  22. then
  23. alias isdarwin=true
  24. else
  25. alias isdarwin=false
  26. fi
  27. ##########################################
  28. safe-cmd(){
  29. type $1 >/dev/null 2>&1 && "$@"
  30. }
  31. test -r /etc/bashrc && . /etc/bashrc
  32. export PS1="\$(prompt_function)\$ "
  33. # PROMPT_COMMAND=prompt_function
  34. export PAGER="less"
  35. export EDITOR="vi"
  36. export VISUAL=$EDITOR
  37. export LESS="-iRM"
  38. # export LC_MESSAGES="C"
  39. # export LANG=ja_JP.UTF-8
  40. # export CDPATH=".:~" # 使い方がよく分からない
  41. export GIT_PAGER=$PAGER
  42. export GIT_EDITOR=$EDITOR
  43. alias ls="ls -CFG $(test "$TERM" == dumb || echo --color=auto) --time-style=long-iso"
  44. alias ll="ls -l"
  45. alias la="ls -A"
  46. alias lla="ls -Al"
  47. alias vl=/usr/share/vim/vimcurrent/macros/less.sh
  48. alias em="emacs -nw"
  49. alias apt-get="sudo apt-get"
  50. alias aptin="apt-get install"
  51. alias aptsearch="apt-cache search"
  52. alias aptshow="apt-cache show"
  53. alias ut="slogin t110414@un001.ecc.u-tokyo.ac.jp"
  54. alias rand="echo \$RANDOM"
  55. alias xunp="file-roller -h"
  56. alias pacome="sudo \paco -D"
  57. alias destroy="rm -rf"
  58. alias psall="ps auxww"
  59. alias g=git
  60. alias q=exit
  61. alias pcalc="python -i -c 'from math import *' "
  62. # alias diff="$(type colordiff >/dev/null 2>&1 && test $TERM != dumb && echo color)diff -u"
  63. # type trash >/dev/null 2>&1 && alias rm=trash
  64. export __MYGITBAREREP="${HOME}/dbx/.git-bare"
  65. git-make-bare-rep(){
  66. test $# -eq 0 && {
  67. echo "specify repository name." 1>&2
  68. return 1
  69. }
  70. dir="${__MYGITBAREREP}/$1.git"
  71. if test -d "$dir"
  72. then
  73. echo "dir $dir already exist!" 1>&2
  74. else
  75. mkdir -p "$dir" &&
  76. pushd "$dir" &&
  77. git init --bare
  78. popd
  79. fi
  80. }
  81. git-add-bare-rep(){
  82. test $# -ne 2 && {
  83. echo "specify repository name and shortname." 1>&2
  84. return 1
  85. }
  86. dir="${__MYGITBAREREP}/$2.git"
  87. git-make-bare-rep $2 &&
  88. git remote add $1 "$dir"
  89. git remote -v
  90. # if test -d "$dir"
  91. # then
  92. # git remote add $1 "$dir"
  93. # git remote -v
  94. # else
  95. # echo "dir $dir does not exist!" 1>&2
  96. # fi
  97. }
  98. bak(){
  99. for file in "$@"
  100. do
  101. cp ${file} ${file}.bak
  102. done
  103. }
  104. di(){
  105. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  106. then
  107. local diffcmd=colordiff
  108. else
  109. local diffcmd=diff
  110. fi
  111. ${diffcmd} -u "$@" | ${PAGER}
  112. }
  113. memo(){
  114. _MEMO="# $*\n"
  115. }
  116. rmmemo(){
  117. _MEMO=""
  118. }
  119. throw-away(){
  120. for file in "$@"
  121. do
  122. mv $file ~/bu/tb
  123. done
  124. }
  125. mkcd(){
  126. mkdir $1
  127. cd $1
  128. }
  129. mkunfddir(){ # create dir if unfound. ?
  130. test -e "$1" || mkdir "$1"
  131. }
  132. gitls(){
  133. for file in `\ls`
  134. do
  135. :
  136. done
  137. }
  138. catclip(){
  139. if iswindows
  140. then
  141. cat /dev/clipboard | tr -d \\r
  142. else
  143. xclip -o -selection "clipboard"
  144. fi
  145. }
  146. setclip(){
  147. if iswindows
  148. then
  149. if test $# -eq 0
  150. then
  151. sed -e 's/$/\r/' | tee /dev/clipboard
  152. else
  153. cat "$@" | sed -e 's/$/\r/' | tee /dev/clipboard
  154. fi
  155. else
  156. if test $# -eq 0
  157. then
  158. xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  159. else
  160. cat "$@" | xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  161. fi
  162. fi
  163. }
  164. p(){
  165. "$@" | $PAGER
  166. }
  167. c(){
  168. "$@" | cat
  169. }
  170. o(){
  171. if [ $# -eq 0 ]
  172. then
  173. local f=.
  174. else
  175. local f="$1"
  176. fi
  177. if iswindows
  178. then
  179. cmd.exe //c start "" "$f"
  180. elif isdarwin
  181. then
  182. open "$f"
  183. else
  184. xdg-open "$f"
  185. fi
  186. }
  187. convmv-sjis2utf8-test(){
  188. convmv -r -f sjis -t utf8 *
  189. }
  190. convmv-sjis2utf8-notest(){
  191. convmv -r -f sjis -t utf8 * --notest
  192. }
  193. dl-my-init-files(){
  194. for file in .bashrc .vimrc .emacs
  195. do
  196. local flag=0
  197. if test -f ~/${file}.new
  198. then
  199. mv ~/${file}.new ~/${file}.old
  200. echo "${file}.new already exist. Rename it to ${file}.old."
  201. flag=1
  202. fi
  203. wget https://dl.dropbox.com/u/1751156/${file} -O ~/${file}.new
  204. local wgetreturn=$?
  205. if test ${flag} -eq 1 -a ${wgetreturn} -eq 0
  206. then
  207. rm ~/${file}.old
  208. echo "${file}.old deleted."
  209. fi
  210. done
  211. }
  212. port-autosync(){
  213. port selfupdate && port sync && port upgrade installed
  214. }
  215. _mygitconfig(){
  216. git config --global user.name '10sr'
  217. git config --global user.email '8slashes+git@gmail.com'
  218. git config --global core.autocrlf false
  219. git config --global color.ui auto
  220. git config --global status.relativePaths false
  221. git config --global status.showUntrackedFiles normal
  222. git config --global alias.graph "log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"
  223. git config --global alias.st "status -s"
  224. git config --global alias.b "branch"
  225. git config --global alias.ci "commit --verbose"
  226. git config --global alias.co "checkout"
  227. git config --global alias.cim "commit --verbose -m"
  228. git config --global alias.di "diff"
  229. git config --global alias.me "merge --no-ff --stat -v"
  230. git config --global alias.ls "!git ls-files | xargs ls -CFG --color=auto --time-style=long-iso"
  231. git config --global alias.ll "!git ls-files | xargs ls -l -CFG --color=auto --time-style=long-iso"
  232. git config --global alias.addi "add -i"
  233. if iswindows; then
  234. git config --global core.fileMode false
  235. fi
  236. }
  237. __my_parse_svn_branch() {
  238. local LANG=C
  239. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  240. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  241. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  242. }
  243. __my_svn_ps1(){
  244. local svn_branch=$(__my_parse_svn_branch)
  245. test "${svn_branch}" == "" || echo ${svn_branch} | xargs printf "$1"
  246. }
  247. prompt_function(){ # used by PS1
  248. local lastreturn=$?
  249. if test "${TERM}" == dumb
  250. then
  251. local c1=""
  252. local c2=""
  253. local c3=""
  254. local cdef=""
  255. else
  256. local c1="\e[33m"
  257. local c2="\e[36m"
  258. local c3="\e[37m"
  259. local cdef="\e[0m"
  260. fi
  261. iscygwin || {
  262. local pwd=$(echo "${PWD}/" | sed -e "s:${HOME}:~:")
  263. local oldpwd=$(echo "${OLDPWD}/" | sed -e "s:${HOME}:~:")
  264. local date=$(LANG=C safe-cmd date +"%a, %d %b %Y %T %z")
  265. local jobnum=$(jobs | wc -l)
  266. }
  267. local git=$(safe-cmd __git_ps1 [GIT:%s])
  268. local svn=$(type svn >/dev/null 2>&1 && safe-cmd __my_svn_ps1 [SVN:%s])
  269. printf "${_MEMO}"
  270. printf " [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}${svn}\n"
  271. printf "${c2}${USER}@${HOSTNAME}${cdef} ${date} ${BASH} ${BASH_VERSION}\n"
  272. printf "shlv:${SHLVL} jobs:${jobnum} last:${lastreturn} "
  273. }
  274. # type date >/dev/null 2>&1 || alias date=":" # "cmd /c echo %time%"
  275. if [ "${EMACS}" = "t" ]; then # emacs shell用
  276. : export PS1="\u@\H \d \t \w\nemacs shell\$ "
  277. elif echo "$EMACS" | grep term >/dev/null 2>&1; then # emacs term用
  278. echo "emacs term"
  279. fi
  280. #Change ANSI Colors
  281. _chengecolors(){
  282. echo -e \
  283. "\e]P0000000" \
  284. "\e]P1cd0000" \
  285. "\e]P200cd00" \
  286. "\e]P3cdcd00" \
  287. "\e]P41e90ff" \
  288. "\e]P5cd00cd" \
  289. "\e]P600cdcd" \
  290. "\e]P7353535" \
  291. "\e]P8666666" \
  292. "\e]P9ff9999" \
  293. "\e]Pa99ff99" \
  294. "\e]Pbffff99" \
  295. "\e]Pc9999ff" \
  296. "\e]Pdff99ff" \
  297. "\e]Pe99ffff" \
  298. "\e]Pfffffff"
  299. }
  300. # printf "\e]P7353535" \
  301. _echocolors(){
  302. echo -e \
  303. "\e[30mBlack\n" \
  304. "\e[31mRed\n" \
  305. "\e[32mGreen\n" \
  306. "\e[33mYellow\n" \
  307. "\e[34mBlue\n" \
  308. "\e[35mMagenta\n" \
  309. "\e[36mCyan\n" \
  310. "\e[37mWhite\n" \
  311. "\e[30;1mBright Black\n" \
  312. "\e[31;1mBright Red\n" \
  313. "\e[32;1mBright Green\n" \
  314. "\e[33;1mBright Yellow\n" \
  315. "\e[34;1mBright Blue\n" \
  316. "\e[35;1mBright Magenta\n" \
  317. "\e[36;1mBright Cyan\n" \
  318. "\e[37;1mBright White\n" \
  319. "\e[0m"
  320. }
  321. safe-cmd stty stop undef # unbind C-s to stop displaying output
  322. #########################
  323. # for windose
  324. winln(){
  325. if test $# -eq 0
  326. then
  327. {
  328. echo "usage: winln TARGET LINK_NAME"
  329. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  330. echo "About other features run 'junction'."
  331. } 1>&2
  332. return 1
  333. else
  334. junction "$2" "$1"
  335. fi
  336. }
  337. ########################
  338. if iscygwin; then
  339. # for cygwin
  340. export TMP=/tmp
  341. export TEMP=/tmp
  342. : alias setclip="tee /dev/clipboard"
  343. : alias catclip="cat /dev/clipboard | tr -d \\r"
  344. alias cygsu="cygstart /cygwinsetup.exe"
  345. alias emacs="CYGWIN=tty emacs -nw"
  346. echo "cygwin bash"
  347. fi
  348. if iswindows; then
  349. # export PS1=" \[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ "
  350. export PS1=" [\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ "
  351. alias ls="ls -CFG $(test "$TERM" == dumb || echo --color=auto)"
  352. fi
  353. #######################
  354. echo "Japanese letters are 表示可能"
  355. safe-cmd diskinfo
  356. type xrandr >/dev/null 2>&1 && {
  357. xrandr | grep --color=never ^Screen
  358. }
  359. safe-cmd finger $USER
  360. LANG=C safe-cmd id