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

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
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
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
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
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
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. replace-cmd(){
  32. type $1 1>/dev/null || alias $1=true
  33. }
  34. export PS1="\$(__my_prompt_function)\$ "
  35. # PROMPT_COMMAND=prompt_function
  36. if false # iswindows
  37. then
  38. export PAGER='tr -d \\r | less'
  39. else
  40. export PAGER="less"
  41. fi
  42. if type vim >/dev/null 2>&1
  43. then
  44. export EDITOR=vim
  45. else
  46. export EDITOR=vi
  47. fi
  48. export VISUAL="$EDITOR"
  49. export LESS="-iRMX"
  50. # export LC_MESSAGES="C"
  51. # export LANG=ja_JP.UTF-8
  52. # export CDPATH=".:~" # 使い方がよく分からない
  53. export GIT_PAGER="$PAGER"
  54. export GIT_EDITOR="$EDITOR"
  55. alias ls="ls -hCFG $(test "$TERM" == dumb || echo --color=auto\ )--time-style=long-iso"
  56. # alias ll="ls -l"
  57. # alias la="ls -A"
  58. # alias lla="ls -Al"
  59. # alias less=""
  60. alias vl=/usr/share/vim/vimcurrent/macros/less.sh
  61. alias em="emacs -nw"
  62. # alias apt-get="sudo apt-get"
  63. alias aptin="apt-get install"
  64. alias aptsearch="apt-cache search"
  65. alias aptshow="apt-cache show"
  66. alias ut="ssh t110414@un001.ecc.u-tokyo.ac.jp"
  67. alias rand="echo \$RANDOM"
  68. alias xunp="file-roller -h"
  69. alias pacome="sudo \paco -D"
  70. alias destroy="rm -rf"
  71. alias psall="ps auxww"
  72. alias g=git
  73. alias q=exit
  74. alias p="$PAGER"
  75. alias c=cat
  76. alias pcalc="python -i -c 'from math import *' "
  77. alias py3=python3
  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 PS1=\$\ 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. _mygitconfig(){
  207. git config --global user.name '10sr'
  208. git config --global user.email '8slashes+git@gmail.com'
  209. git config --global core.autocrlf false
  210. git config --global color.ui auto
  211. git config --global status.relativePaths false
  212. git config --global status.showUntrackedFiles normal
  213. git config --global alias.graph "log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"
  214. git config --global alias.st "status -s"
  215. git config --global alias.b "branch"
  216. git config --global alias.ci "commit --verbose"
  217. git config --global alias.co "checkout"
  218. git config --global alias.cim "commit --verbose -m"
  219. git config --global alias.di "diff"
  220. git config --global alias.me "merge --no-ff --stat -v"
  221. git config --global alias.ls "ls-files -v --full-name"
  222. git config --global alias.sl "!sl"
  223. # git config --global alias.my-ls "ls-files | xargs ls"
  224. # git config --global alias.ll "!git ls-files | xargs ls -l -CFG --color=auto --time-style=long-iso"
  225. git config --global alias.addi "add -i"
  226. if iswindows; then
  227. git config --global core.fileMode false
  228. fi
  229. }
  230. if type _git >/dev/null 2>&1 # enable programmable completion of g
  231. then
  232. complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
  233. || complete -o default -o nospace -F _git g
  234. fi
  235. __my_parse_svn_branch() {
  236. local LANG=C
  237. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  238. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  239. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  240. }
  241. __my_svn_ps1(){
  242. local svn_branch=$(__my_parse_svn_branch)
  243. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  244. }
  245. __my_prompt_function(){ # used by PS1
  246. local lastreturn=$?
  247. if test "${TERM}" == dumb
  248. then
  249. local c1=
  250. local c2=
  251. local c3=
  252. local cdef=
  253. else
  254. local c1="\e[33m"
  255. local c2="\e[36m"
  256. local c3="\e[37m"
  257. local cdef="\e[0m"
  258. fi
  259. if iswindows
  260. then
  261. local pwd=$PWD
  262. local oldpwd=$OLDPWD
  263. local jobnum=
  264. if git branch >/dev/null 2>&1
  265. then
  266. local git="[GIT]"
  267. else
  268. local git=
  269. fi
  270. local date=$(/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%')
  271. :
  272. else
  273. local pwd=$(echo "${PWD}/" | sed -e "s#${HOME}#~#")
  274. local oldpwd=$(echo "${OLDPWD}/" | sed -e "s#${HOME}#~#")
  275. local jobnum=$(jobs | wc -l)
  276. local git=$(__try_exec __git_ps1 [GIT:%s])
  277. local date=$(LANG=C __try_exec date +"%a, %d %b %Y %T %z")
  278. fi
  279. local svn=$(type svn >/dev/null 2>&1 && __try_exec __my_svn_ps1 [SVN:%s])
  280. printf "${_MEMO}"
  281. printf "$(test -f ~/.prompt.sh && bash ~/.prompt.sh)\n"
  282. printf " [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}${svn}\n"
  283. printf "${c2}${USER}@${HOSTNAME}${cdef} ${date} ${BASH} ${BASH_VERSION}\n"
  284. printf "shlv:${SHLVL} jobs:${jobnum} last:${lastreturn} "
  285. }
  286. # type date >/dev/null 2>&1 || alias date=":" # "cmd /c echo %time%"
  287. if [ "${EMACS}" = "t" ]; then # emacs shell用
  288. true export PS1="\u@\H \d \t \w\nemacs shell\$ "
  289. elif echo "$EMACS" | grep term >/dev/null 2>&1; then # emacs term用
  290. echo "emacs term"
  291. fi
  292. #Change ANSI Colors
  293. _chengecolors(){
  294. echo -e \
  295. "\e]P0000000" \
  296. "\e]P1cd0000" \
  297. "\e]P200cd00" \
  298. "\e]P3cdcd00" \
  299. "\e]P41e90ff" \
  300. "\e]P5cd00cd" \
  301. "\e]P600cdcd" \
  302. "\e]P7353535" \
  303. "\e]P8666666" \
  304. "\e]P9ff9999" \
  305. "\e]Pa99ff99" \
  306. "\e]Pbffff99" \
  307. "\e]Pc9999ff" \
  308. "\e]Pdff99ff" \
  309. "\e]Pe99ffff" \
  310. "\e]Pfffffff"
  311. }
  312. # printf "\e]P7353535" \
  313. _echocolors(){
  314. echo -e \
  315. "\e[30mBlack\n" \
  316. "\e[31mRed\n" \
  317. "\e[32mGreen\n" \
  318. "\e[33mYellow\n" \
  319. "\e[34mBlue\n" \
  320. "\e[35mMagenta\n" \
  321. "\e[36mCyan\n" \
  322. "\e[37mWhite\n" \
  323. "\e[30;1mBright Black\n" \
  324. "\e[31;1mBright Red\n" \
  325. "\e[32;1mBright Green\n" \
  326. "\e[33;1mBright Yellow\n" \
  327. "\e[34;1mBright Blue\n" \
  328. "\e[35;1mBright Magenta\n" \
  329. "\e[36;1mBright Cyan\n" \
  330. "\e[37;1mBright White\n" \
  331. "\e[0m"
  332. }
  333. null type stty && {
  334. stty stop undef # unbind C-s to stop displaying output
  335. stty erase '^h'
  336. }
  337. #########################
  338. # for windose
  339. winln(){
  340. if test $# -eq 0
  341. then
  342. {
  343. echo "usage: winln TARGET LINK_NAME"
  344. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  345. echo "About other features run 'junction'."
  346. } 1>&2
  347. return 1
  348. else
  349. junction "$2" "$1"
  350. fi
  351. }
  352. ########################
  353. if iscygwin; then
  354. alias cygsu="cygstart /cygwinsetup.exe"
  355. alias emacs="CYGWIN=tty emacs -nw"
  356. echo "cygwin bash"
  357. fi
  358. if iswindows; then
  359. # export TMP=/tmp
  360. # export TEMP=/tmp
  361. # export PS1=" \[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ "
  362. # export PS1=" [\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ "
  363. alias ls="ls -CFG $(test "$TERM" == dumb || echo --color=auto)"
  364. export USER=$USERNAME
  365. fi
  366. #######################
  367. _testjp(){
  368. echo "Japanese letters are 表示可能"
  369. }
  370. _testjp
  371. uname -a
  372. test -f /etc/issue.net && cat /etc/issue.net
  373. __try_exec diskinfo
  374. ! isdarwin && test -n "${DESKTOP_SESSION}" && type xrandr >/dev/null 2>&1 && {
  375. xrandr | grep --color=never ^Screen
  376. }
  377. iswindows || __try_exec finger $USER
  378. LANG=C __try_exec id