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

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