Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

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