Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

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