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.
 
 
 
 
 
 

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