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

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