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

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