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

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