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.
 
 
 
 
 
 

349 lines
8.6 KiB

  1. #!/bin/bash
  2. # 外部ファイルの読み込み
  3. # test -r ~/filepath && . ~/filepath
  4. # ln SRC DST
  5. ##########################################
  6. safe-cmd(){
  7. type $1 >/dev/null 2>&1 && "$@"
  8. }
  9. test -r /etc/bashrc && . /etc/bashrc
  10. export PS1="\$(prompt_function)\$ "
  11. # PROMPT_COMMAND=prompt_function
  12. export PAGER="less"
  13. export EDITOR="vim"
  14. export VISUAL=$EDITOR
  15. export LESS="-iRM"
  16. # export LC_MESSAGES="C"
  17. # export LANG=ja_JP.UTF-8
  18. # export CDPATH=".:~" # 使い方がよく分からない
  19. export GIT_PAGER=$PAGER
  20. export GIT_EDITOR=$EDITOR
  21. alias ls="ls -CFG $(test "$TERM" == dumb || echo --color=auto) --time-style=long-iso"
  22. alias ll="ls -l"
  23. alias la="ls -A"
  24. alias lla="ls -Al"
  25. alias vl=/usr/share/vim/vimcurrent/macros/less.sh
  26. alias em="emacs -nw"
  27. alias apt-get="sudo apt-get"
  28. alias aptin="apt-get install"
  29. alias aptsearch="apt-cache search"
  30. alias aptshow="apt-cache show"
  31. alias ut="slogin t110414@un001.ecc.u-tokyo.ac.jp"
  32. alias rand="echo \$RANDOM"
  33. alias xunp="file-roller -h"
  34. alias pacome="sudo \paco -D"
  35. alias destroy="rm -rf"
  36. alias psall="ps auxww"
  37. alias g=git
  38. alias q=exit
  39. alias pcalc="python -i -c 'from math import *' "
  40. # alias diff="$(type colordiff >/dev/null 2>&1 && test $TERM != dumb && echo color)diff -u"
  41. # type trash >/dev/null 2>&1 && alias rm=trash
  42. bak(){
  43. for file in "$@"
  44. do
  45. cp ${file} ${file}.bak
  46. done
  47. }
  48. di(){
  49. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  50. then
  51. local diffcmd=colordiff
  52. else
  53. local diffcmd=diff
  54. fi
  55. ${diffcmd} -u "$@" | ${PAGER}
  56. }
  57. memo(){
  58. _MEMO="# $*\n"
  59. }
  60. rmmemo(){
  61. _MEMO=""
  62. }
  63. throw-away(){
  64. for file in "$@"
  65. do
  66. mv $file ~/bu/tb
  67. done
  68. }
  69. mkcd(){
  70. mkdir $1
  71. cd $1
  72. }
  73. mkunfddir(){ # create dir if unfound. ?
  74. test -e "$1" || mkdir "$1"
  75. }
  76. gitls(){
  77. for file in `\ls`
  78. do
  79. :
  80. done
  81. }
  82. catclip(){
  83. if iswindows
  84. then
  85. cat /dev/clipboard | tr -d \\r
  86. else
  87. xclip -o -selection "clipboard"
  88. fi
  89. }
  90. setclip(){
  91. if iswindows
  92. then
  93. if test $# -eq 0
  94. then
  95. sed -e 's/$/\r/' | tee /dev/clipboard
  96. else
  97. cat "$@" | sed -e 's/$/\r/' | tee /dev/clipboard
  98. fi
  99. else
  100. if test $# -eq 0
  101. then
  102. xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  103. else
  104. cat "$@" | xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  105. fi
  106. fi
  107. }
  108. p(){
  109. "$@" | $PAGER
  110. }
  111. c(){
  112. "$@" | cat
  113. }
  114. o(){
  115. if [ $# -eq 0 ]
  116. then
  117. local f=.
  118. else
  119. local f="$1"
  120. fi
  121. if iswindows
  122. then
  123. cmd.exe //c start "" "$f"
  124. elif isdarwin
  125. then
  126. open "$f"
  127. else
  128. xdg-open "$f"
  129. fi
  130. }
  131. convmv-sjis2utf8-test(){
  132. convmv -r -f sjis -t utf8 *
  133. }
  134. convmv-sjis2utf8-notest(){
  135. convmv -r -f sjis -t utf8 * --notest
  136. }
  137. dl-my-init-files(){
  138. for file in .bashrc .vimrc .emacs
  139. do
  140. local flag=0
  141. if test -f ~/${file}.new
  142. then
  143. mv ~/${file}.new ~/${file}.old
  144. echo "${file}.new already exist. Rename it to ${file}.old."
  145. flag=1
  146. fi
  147. wget https://dl.dropbox.com/u/1751156/${file} -O ~/${file}.new
  148. local wgetreturn=$?
  149. if test ${flag} -eq 1 -a ${wgetreturn} -eq 0
  150. then
  151. rm ~/${file}.old
  152. echo "${file}.old deleted."
  153. fi
  154. done
  155. }
  156. port-autosync(){
  157. port selfupdate && port sync && port upgrade installed
  158. }
  159. _mygitconfig(){
  160. git config --global user.name '10sr'
  161. git config --global user.email '8slashes+git@gmail.com'
  162. git config --global core.autocrlf false
  163. git config --global color.ui auto
  164. git config --global status.relativePaths false
  165. git config --global status.showUntrackedFiles normal
  166. git config --global alias.graph "log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"
  167. git config --global alias.st "status -s"
  168. git config --global alias.b "branch"
  169. git config --global alias.ci "commit --verbose"
  170. git config --global alias.co "checkout"
  171. git config --global alias.cim "commit --verbose -m"
  172. git config --global alias.di "diff"
  173. git config --global alias.me "merge --no-ff --stat -v"
  174. git config --global alias.ls "!git ls-files | xargs ls -CFG --color=auto --time-style=long-iso"
  175. git config --global alias.ll "!git ls-files | xargs ls -l -CFG --color=auto --time-style=long-iso"
  176. git config --global alias.addi "add -i"
  177. if iswindows; then
  178. git config --global core.fileMode false
  179. fi
  180. }
  181. __my_parse_svn_branch() {
  182. local LANG=C
  183. local svn_url=$(svn info 2>/dev/null | sed -ne 's#^URL: ##p')
  184. local svn_repository_root=$(svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p')
  185. echo ${svn_url} | sed -e 's#^'"${svn_repository_root}"'##g' | awk '{print $1}'
  186. }
  187. __my_svn_ps1(){
  188. local svn_branch=$(__my_parse_svn_branch)
  189. test "${svn_branch}" == "" || echo ${svn_branch} | xargs printf "$1"
  190. }
  191. prompt_function(){ # used by PS1
  192. local lastreturn=$?
  193. if test "${TERM}" == dumb
  194. then
  195. local c1=""
  196. local c2=""
  197. local c3=""
  198. local cdef=""
  199. else
  200. local c1="\e[33m"
  201. local c2="\e[36m"
  202. local c3="\e[37m"
  203. local cdef="\e[0m"
  204. fi
  205. iscygwin || {
  206. local pwd=$(echo "${PWD}/" | sed -e "s:${HOME}:~:")
  207. local oldpwd=$(echo "${OLDPWD}/" | sed -e "s:${HOME}:~:")
  208. local date=$(LANG=C safe-cmd date +"%a, %d %b %Y %T %z")
  209. local jobnum=$(jobs | wc -l)
  210. }
  211. local git=$(safe-cmd __git_ps1 [GIT:%s])
  212. local svn=$(type svn >/dev/null 2>&1 && safe-cmd __my_svn_ps1 [SVN:%s])
  213. printf "${_MEMO}"
  214. printf " [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}${svn}\n"
  215. printf "${c2}${USER}@${HOSTNAME}${cdef} ${date} ${BASH} ${BASH_VERSION}\n"
  216. printf "shlv:${SHLVL} jobs:${jobnum} last:${lastreturn} "
  217. }
  218. # type date >/dev/null 2>&1 || alias date=":" # "cmd /c echo %time%"
  219. if [ "${EMACS}" = "t" ]; then # emacs shell用
  220. : export PS1="\u@\H \d \t \w\nemacs shell\$ "
  221. elif echo "$EMACS" | grep term >/dev/null 2>&1; then # emacs term用
  222. echo "emacs term"
  223. fi
  224. #Change ANSI Colors
  225. _chengecolors(){
  226. echo -e \
  227. "\e]P0000000" \
  228. "\e]P1cd0000" \
  229. "\e]P200cd00" \
  230. "\e]P3cdcd00" \
  231. "\e]P41e90ff" \
  232. "\e]P5cd00cd" \
  233. "\e]P600cdcd" \
  234. "\e]P7353535" \
  235. "\e]P8666666" \
  236. "\e]P9ff9999" \
  237. "\e]Pa99ff99" \
  238. "\e]Pbffff99" \
  239. "\e]Pc9999ff" \
  240. "\e]Pdff99ff" \
  241. "\e]Pe99ffff" \
  242. "\e]Pfffffff"
  243. }
  244. # printf "\e]P7353535" \
  245. _echocolors(){
  246. echo -e \
  247. "\e[30mBlack\n" \
  248. "\e[31mRed\n" \
  249. "\e[32mGreen\n" \
  250. "\e[33mYellow\n" \
  251. "\e[34mBlue\n" \
  252. "\e[35mMagenta\n" \
  253. "\e[36mCyan\n" \
  254. "\e[37mWhite\n" \
  255. "\e[30;1mBright Black\n" \
  256. "\e[31;1mBright Red\n" \
  257. "\e[32;1mBright Green\n" \
  258. "\e[33;1mBright Yellow\n" \
  259. "\e[34;1mBright Blue\n" \
  260. "\e[35;1mBright Magenta\n" \
  261. "\e[36;1mBright Cyan\n" \
  262. "\e[37;1mBright White\n" \
  263. "\e[0m"
  264. }
  265. safe-cmd stty stop undef # unbind C-s to stop displaying output
  266. ##########################
  267. # system type
  268. # $OSTYPEとか使えるのかな
  269. iswindows(){
  270. # uname | grep -iE 'windows|MINGW' >/dev/null 2>&1
  271. iscygwin || ismsys
  272. }
  273. ismsys(){
  274. uname | grep -E "^MINGW32" >/dev/null 2>&1
  275. }
  276. iscygwin(){
  277. uname | grep -E "^CYGWIN" >/dev/null 2>&1
  278. }
  279. isdarwin(){
  280. uname | grep -E 'Darwin' >/dev/null 2>&1
  281. }
  282. #########################
  283. # for windose
  284. winln(){
  285. if test $# -eq 0
  286. then
  287. {
  288. echo "usage: winln TARGET LINK_NAME"
  289. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  290. echo "About other features run 'junction'."
  291. } 1>&2
  292. return 1
  293. else
  294. junction "$2" "$1"
  295. fi
  296. }
  297. ########################
  298. if iscygwin; then
  299. # for cygwin
  300. export TMP=/tmp
  301. export TEMP=/tmp
  302. : alias setclip="tee /dev/clipboard"
  303. : alias catclip="cat /dev/clipboard | tr -d \\r"
  304. alias cygsu="cygstart /cygwinsetup.exe"
  305. alias emacs="CYGWIN=tty emacs -nw"
  306. echo "cygwin bash"
  307. fi
  308. if iswindows; then
  309. # export PS1=" \[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ "
  310. export PS1=" [\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ "
  311. alias ls="ls -CFG $(test "$TERM" == dumb || echo --color=auto)"
  312. fi
  313. #######################
  314. echo "Japanese letters are 表示可能"
  315. safe-cmd diskinfo
  316. type xrandr >/dev/null 2>&1 && {
  317. xrandr | grep --color=never ^Screen
  318. }
  319. safe-cmd finger $USER
  320. LANG=C safe-cmd id