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