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