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 10 KiB

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