You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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