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.
 
 
 
 
 
 

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