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.
 
 
 
 
 
 

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