Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

314 строки
7.6 KiB

  1. #!/bin/bash
  2. # 外部ファイルの読み込み
  3. # test -r ~/filepath && . ~/filepath
  4. # ln SRC DST
  5. ##########################################
  6. test -r /etc/bashrc && . /etc/bashrc
  7. safe-cmd(){
  8. type $1 >/dev/null 2>&1 && "$@"
  9. }
  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 emacs="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 diff="$(type colordiff >/dev/null 2>&1 && test $TERM != dumb && echo color)diff -u"
  40. # type trash >/dev/null 2>&1 && alias rm=trash
  41. di(){
  42. if type colordiff >/dev/null 2>&1 && test $TERM != dumb
  43. then
  44. local diffcmd=colordiff
  45. else
  46. local diffcmd=diff
  47. fi
  48. ${diffcmd} -u "$@" | ${PAGER}
  49. }
  50. memo(){
  51. _MEMO="# $*\n"
  52. }
  53. rmmemo(){
  54. _MEMO=""
  55. }
  56. throw-away(){
  57. for file in "$@"
  58. do
  59. mv $file ~/bu/tb
  60. done
  61. }
  62. mkcd(){
  63. mkdir $1
  64. cd $1
  65. }
  66. mkunfddir(){ # create dir if unfound. ?
  67. test -e "$1" || mkdir "$1"
  68. }
  69. gitls(){
  70. for file in `\ls`
  71. do
  72. :
  73. done
  74. }
  75. catclip(){
  76. if iscygwin
  77. then
  78. cat /dev/clipboard | tr -d \\r
  79. else
  80. xclip -o -selection "clipboard"
  81. fi
  82. }
  83. setclip(){
  84. if iscygwin
  85. then
  86. if test $# -eq 0
  87. then
  88. sed -e 's/$/\r/' | tee /dev/clipboard
  89. else
  90. cat "$@" | sed -e 's/$/\r/' | tee /dev/clipboard
  91. fi
  92. else
  93. if test $# -eq 0
  94. then
  95. xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  96. else
  97. cat "$@" | xclip -i -f -selection "primary" | xclip -i -f -selection "clipboard"
  98. fi
  99. fi
  100. }
  101. p(){
  102. "$@" | $PAGER
  103. }
  104. c(){
  105. "$@" | cat
  106. }
  107. o(){
  108. if [ $# -eq 0 ]
  109. then
  110. local f=.
  111. else
  112. local f="$1"
  113. fi
  114. if iswindows
  115. then
  116. cmd.exe //c start "" "$f"
  117. elif isdarwin
  118. then
  119. open "$f"
  120. else
  121. xdg-open "$f"
  122. fi
  123. }
  124. convmv-sjis2utf8-test(){
  125. convmv -r -f sjis -t utf8 *
  126. }
  127. convmv-sjis2utf8-notest(){
  128. convmv -r -f sjis -t utf8 * --notest
  129. }
  130. dl-my-init-files(){
  131. for file in .bashrc .vimrc .emacs
  132. do
  133. local flag=0
  134. if test -f ~/${file}.new
  135. then
  136. mv ~/${file}.new ~/${file}.old
  137. echo "${file}.new already exist. Rename it to ${file}.old."
  138. flag=1
  139. fi
  140. wget https://dl.dropbox.com/u/1751156/${file} -O ~/${file}.new
  141. local wgetreturn=$?
  142. if test ${flag} -eq 1 -a ${wgetreturn} -eq 0
  143. then
  144. rm ~/${file}.old
  145. echo "${file}.old deleted."
  146. fi
  147. done
  148. }
  149. port-autosync(){
  150. port selfupdate && port sync && port upgrade installed
  151. }
  152. _mygitconfig(){
  153. git config --global user.name "10sr"
  154. git config --global user.email sr10@users.sourceforge.jp
  155. git config --global core.autocrlf false
  156. git config --global color.ui auto
  157. git config --global status.relativePaths false
  158. git config --global status.showUntrackedFiles no
  159. git config --global alias.graph "log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"
  160. git config --global alias.st "status"
  161. git config --global alias.b "branch"
  162. git config --global alias.ci "commit --verbose"
  163. git config --global alias.co "checkout"
  164. git config --global alias.cim "commit --verbose -m"
  165. git config --global alias.di "diff"
  166. git config --global alias.ls "!git ls-files | xargs ls -CFG --color=auto --time-style=long-iso"
  167. git config --global alias.ll "!git ls-files | xargs ls -l -CFG --color=auto --time-style=long-iso"
  168. git config --global alias.addi "add -i"
  169. }
  170. prompt_function(){ # used by PS1
  171. local lastreturn=$?
  172. if test "${TERM}" == dumb
  173. then
  174. local c1=""
  175. local c2=""
  176. local c3=""
  177. local cdef=""
  178. else
  179. local c1="\e[33m"
  180. local c2="\e[36m"
  181. local c3="\e[37m"
  182. local cdef="\e[0m"
  183. fi
  184. local pwd=$(echo "${PWD}/" | sed -e "s:${HOME}:~:")
  185. local oldpwd=$(echo "${OLDPWD}/" | sed -e "s:${HOME}:~:")
  186. local date=$(LANG=C safe-cmd date +"%a, %d %b %Y %T %z")
  187. local jobnum=$(jobs | wc -l)
  188. local git=$(safe-cmd __git_ps1 [GIT:%s])
  189. printf "${_MEMO}"
  190. printf " [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}\n"
  191. printf "${c2}${USER}@${HOSTNAME}${cdef} ${date} ${BASH} ${BASH_VERSION}\n"
  192. printf "shlv:${SHLVL} jobs:${jobnum} last:${lastreturn} "
  193. }
  194. # type date >/dev/null 2>&1 || alias date=":" # "cmd /c echo %time%"
  195. if [ "${EMACS}" = "t" ]; then # emacs shell用
  196. : export PS1="\u@\H \d \t \w\nemacs shell\$ "
  197. elif echo "$EMACS" | grep term >/dev/null 2>&1; then # emacs term用
  198. echo "emacs term"
  199. fi
  200. # #Change ANSI Colors
  201. # if [ $TERM = "xterm" ]
  202. # then
  203. # echo -e \
  204. # "\e]P0000000" \
  205. # "\e]P1cd0000" \
  206. # "\e]P200cd00" \
  207. # "\e]P3cdcd00" \
  208. # "\e]P41e90ff" \
  209. # "\e]P5cd00cd" \
  210. # "\e]P600cdcd" \
  211. # "\e]P7353535" \
  212. # "\e]P8666666" \
  213. # "\e]P9ff9999" \
  214. # "\e]Pa99ff99" \
  215. # "\e]Pbffff99" \
  216. # "\e]Pc9999ff" \
  217. # "\e]Pdff99ff" \
  218. # "\e]Pe99ffff" \
  219. # "\e]Pfffffff"
  220. # fi
  221. # printf "\e]P7353535" \
  222. _echocolors(){
  223. echo -e \
  224. "\e[30mBlack\n" \
  225. "\e[31mRed\n" \
  226. "\e[32mGreen\n" \
  227. "\e[33mYellow\n" \
  228. "\e[34mBlue\n" \
  229. "\e[35mMagenta\n" \
  230. "\e[36mCyan\n" \
  231. "\e[37mWhite\n" \
  232. "\e[30;1mBright Black\n" \
  233. "\e[31;1mBright Red\n" \
  234. "\e[32;1mBright Green\n" \
  235. "\e[33;1mBright Yellow\n" \
  236. "\e[34;1mBright Blue\n" \
  237. "\e[35;1mBright Magenta\n" \
  238. "\e[36;1mBright Cyan\n" \
  239. "\e[37;1mBright White\n" \
  240. "\e[0m"
  241. }
  242. safe-cmd stty stop undef # unbind C-s to stop displaying output
  243. ##########################
  244. # system type
  245. # $OSTYPEとか使えるのかな
  246. iswindows(){
  247. uname | grep -iE 'windows|MINGW' >/dev/null 2>&1
  248. }
  249. ismsys(){
  250. false
  251. }
  252. iscygwin(){
  253. uname | grep -E "^CYGWIN" >/dev/null 2>&1
  254. }
  255. isdarwin(){
  256. uname | grep -E 'Darwin' >/dev/null 2>&1
  257. }
  258. #########################
  259. # for windose
  260. winln(){
  261. if test $# -eq 0
  262. then
  263. {
  264. echo "usage: winln TARGET LINK_NAME"
  265. echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)."
  266. echo "About other features run 'junction'."
  267. } 1>&2
  268. return 1
  269. else
  270. junction "$2" "$1"
  271. fi
  272. }
  273. ########################
  274. if iscygwin; then
  275. # for cygwin
  276. export TMP=/tmp
  277. export TEMP=/tmp
  278. : alias setclip="tee /dev/clipboard"
  279. : alias catclip="cat /dev/clipboard | tr -d \\r"
  280. alias cygsu="cygstart /cygwinsetup.exe"
  281. alias emacs="CYGWIN=tty emacs"
  282. echo "cygwin bash"
  283. fi
  284. #######################
  285. echo "Japanese letters are 表示可能"
  286. safe-cmd diskinfo
  287. safe-cmd finger $USER
  288. LANG=C safe-cmd id