25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

.bashrc 10 KiB

12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. __my_parse_svn_branch() {
  244. local LANG=C
  245. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  246. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  247. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  248. }
  249. __my_svn_ps1(){
  250. local svn_branch=$(__my_parse_svn_branch)
  251. test -n "${svn_branch}" && printf "$1" "{$svn_branch}"
  252. }
  253. replace-cmd date
  254. replace-cmd __my_svn_ps1
  255. __my_prompt_function(){ # used by PS1
  256. local lastreturn=$?
  257. if test "${TERM}" == dumb
  258. then
  259. local c1=
  260. local c2=
  261. local c3=
  262. local cdef=
  263. else
  264. local c1="\e[33m"
  265. local c2="\e[36m"
  266. local c3="\e[37m"
  267. local cdef="\e[0m"
  268. fi
  269. if iswindows
  270. then
  271. local pwd=$PWD
  272. local oldpwd=$OLDPWD
  273. local jobnum=
  274. if git branch >/dev/null 2>&1
  275. then
  276. local git="[GIT]"
  277. else
  278. local git=
  279. fi
  280. local date=$(/c/Windows/System32/cmd.exe //c 'echo %DATE%-%TIME%')
  281. :
  282. else
  283. local pwd=$(echo "${PWD}/" | sed -e "s#${HOME}#~#")
  284. local oldpwd=$(echo "${OLDPWD}/" | sed -e "s#${HOME}#~#")
  285. local jobnum=$(jobs | wc -l)
  286. local git=$(safe-cmd __git_ps1 [GIT:%s])
  287. local date=$(LANG=C safe-cmd date +"%a, %d %b %Y %T %z")
  288. fi
  289. local svn=$(type svn >/dev/null 2>&1 && safe-cmd __my_svn_ps1 [SVN:%s])
  290. printf "${_MEMO}"
  291. printf "$(test -f ~/.prompt.sh && bash ~/.prompt.sh)\n"
  292. printf " [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}${svn}\n"
  293. printf "${c2}${USER}@${HOSTNAME}${cdef} ${date} ${BASH} ${BASH_VERSION}\n"
  294. printf "shlv:${SHLVL} jobs:${jobnum} last:${lastreturn} "
  295. }
  296. # type date >/dev/null 2>&1 || alias date=":" # "cmd /c echo %time%"
  297. if [ "${EMACS}" = "t" ]; then # emacs shell用
  298. : export PS1="\u@\H \d \t \w\nemacs shell\$ "
  299. elif echo "$EMACS" | grep term >/dev/null 2>&1; then # emacs term用
  300. echo "emacs term"
  301. fi
  302. #Change ANSI Colors
  303. _chengecolors(){
  304. echo -e \
  305. "\e]P0000000" \
  306. "\e]P1cd0000" \
  307. "\e]P200cd00" \
  308. "\e]P3cdcd00" \
  309. "\e]P41e90ff" \
  310. "\e]P5cd00cd" \
  311. "\e]P600cdcd" \
  312. "\e]P7353535" \
  313. "\e]P8666666" \
  314. "\e]P9ff9999" \
  315. "\e]Pa99ff99" \
  316. "\e]Pbffff99" \
  317. "\e]Pc9999ff" \
  318. "\e]Pdff99ff" \
  319. "\e]Pe99ffff" \
  320. "\e]Pfffffff"
  321. }
  322. # printf "\e]P7353535" \
  323. _echocolors(){
  324. echo -e \
  325. "\e[30mBlack\n" \
  326. "\e[31mRed\n" \
  327. "\e[32mGreen\n" \
  328. "\e[33mYellow\n" \
  329. "\e[34mBlue\n" \
  330. "\e[35mMagenta\n" \
  331. "\e[36mCyan\n" \
  332. "\e[37mWhite\n" \
  333. "\e[30;1mBright Black\n" \
  334. "\e[31;1mBright Red\n" \
  335. "\e[32;1mBright Green\n" \
  336. "\e[33;1mBright Yellow\n" \
  337. "\e[34;1mBright Blue\n" \
  338. "\e[35;1mBright Magenta\n" \
  339. "\e[36;1mBright Cyan\n" \
  340. "\e[37;1mBright White\n" \
  341. "\e[0m"
  342. }
  343. safe-cmd stty stop undef # unbind C-s to stop displaying output
  344. #########################
  345. # for windose
  346. winln(){
  347. if test $# -eq 0
  348. then
  349. {
  350. echo "usage: winln TARGET LINK_NAME"
  351. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  352. echo "About other features run 'junction'."
  353. } 1>&2
  354. return 1
  355. else
  356. junction "$2" "$1"
  357. fi
  358. }
  359. ########################
  360. if iscygwin; then
  361. alias cygsu="cygstart /cygwinsetup.exe"
  362. alias emacs="CYGWIN=tty emacs -nw"
  363. echo "cygwin bash"
  364. fi
  365. if iswindows; then
  366. # export TMP=/tmp
  367. # export TEMP=/tmp
  368. # export PS1=" \[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ "
  369. # export PS1=" [\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ "
  370. alias ls="ls -CFG $(test "$TERM" == dumb || echo --color=auto)"
  371. export USER=$USERNAME
  372. fi
  373. #######################
  374. _testjp(){
  375. echo "Japanese letters are 表示可能"
  376. }
  377. _testjp
  378. uname -a
  379. test -f /etc/issue.net && cat /etc/issue.net
  380. safe-cmd diskinfo
  381. ! isdarwin && test -n "${DESKTOP_SESSION}" && type xrandr >/dev/null 2>&1 && {
  382. xrandr | grep --color=never ^Screen
  383. }
  384. ! iswindows && safe-cmd finger $USER
  385. LANG=C safe-cmd id