您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

392 行
9.6 KiB

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