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.
 
 
 
 
 
 

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