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.
 
 
 
 
 
 

408 lines
9.6 KiB

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