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.
 
 
 
 
 
 

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