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.
 
 
 
 
 
 

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