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.
 
 
 
 
 
 

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