Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

399 řádky
9.7 KiB

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