25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

305 satır
6.8 KiB

  1. #!/bin/sh
  2. # setup.sh --- 10sr setup script
  3. __setups="gitconf tmux scripts darwin dirs selfupdate"
  4. __homelocal="$HOME/.local"
  5. __homevar="$HOME/.var"
  6. ###########################
  7. # utils
  8. _download(){
  9. # download <url> <file>
  10. if type wget >/dev/null 2>&1
  11. then
  12. wget $__my_wget_options "$1" -O "$2"
  13. elif type curl >/dev/null 2>&1
  14. then
  15. curl --url "$1" --output "$2"
  16. fi
  17. }
  18. #############################
  19. # gen_common
  20. # Generate ~/.shrc.common, which contains system infos and is sourced from
  21. # setup.sh (this file) and dotfiles/shrc .
  22. # This functions is always called.
  23. # this variable must consistent with shrc
  24. __shrc_common="$HOME/.shrc.common"
  25. gen_common(){
  26. test -f "$__shrc_common" && rm -- "$__shrc_common"
  27. __ismsys=false
  28. __iscygwin=false
  29. __iswindows=false
  30. __isdarwin=false
  31. __isfreebsd=false
  32. __isbsd=false
  33. __islinux=false
  34. # $OSTYPE is another choice. which is better?
  35. # sh on FreeBSD does not define OSTYPE
  36. case `uname` in
  37. (MINGW*) __ismsys=true ;;
  38. (CYGWIN*) __iscygwin=true ;;
  39. (Darwin*) __isdarwin=true ;;
  40. (FreeBSD*) __isfreebsd=true ;;
  41. (Linux*) __islinux=true ;;
  42. esac
  43. ( $__ismsys || $__iscygwin ) && __iswindows=true
  44. # is this true?
  45. ( $__isdarwin || $__freebsd ) && __isbsd=true
  46. cat <<__EOC__ >"$__shrc_common"
  47. #!/bin/sh
  48. # $__shrc_common
  49. # Automatically generated by $0
  50. ismsys=$__ismsys
  51. iscygwin=$__iscygwin
  52. iswindows=$__iswindows
  53. isdarwin=$__isdarwin
  54. isfreebsd=$__isfreebsd
  55. isbsd=$__isbsd
  56. islinux=$__islinux
  57. __homelocal="$__homelocal"
  58. __homevar="$__homevar"
  59. __EOC__
  60. }
  61. ###############################
  62. # selfupdate
  63. __setup_url="https://raw.github.com/10sr/dotfiles/master/setup.sh"
  64. setup_selfupdate(){
  65. if test -z "$SETUP_OUTPUT"
  66. then
  67. echo SETUP_OUTPUT is not set.
  68. echo Ignore selfupdate.
  69. return
  70. fi
  71. _download $__setup_url "$SETUP_OUTPUT"
  72. }
  73. ################################
  74. # git_configs
  75. setup_gitconf(){
  76. if ! command -v git >/dev/null
  77. then
  78. echo "git not found"
  79. return 1
  80. fi
  81. _gc="git config --global"
  82. $_gc user.name '10sr'
  83. $_gc user.email '8slashes+git@gmail.com'
  84. $_gc core.autocrlf false
  85. $_gc core.excludesfile '~/.gitignore'
  86. $_gc color.ui auto
  87. $_gc status.relativePaths false
  88. $_gc status.showUntrackedFiles normal
  89. $_gc log.date iso
  90. command -v xz >/dev/null && \
  91. $_gc tar.txz.command "xz -c"
  92. $_gc push.default current
  93. $_gc alias.graph "log --graph --date-order -C -M --pretty=tformat:\"%C(green)%h%C(reset) %C(white)%ad%C(reset) %C(red)%an%C(reset)%C(yellow)%d%C(reset) %C(white bold)%s%C(reset)\" --all --date=iso -n 499"
  94. $_gc alias.st "status -s -b"
  95. $_gc alias.b "branch"
  96. $_gc alias.sb "show-branch"
  97. $_gc alias.ci "commit --verbose"
  98. $_gc alias.co "checkout"
  99. $_gc alias.cim "commit --verbose -m"
  100. $_gc alias.di "diff --color"
  101. $_gc alias.me "merge --no-ff --stat -v"
  102. $_gc alias.gr "grep -n"
  103. $_gc alias.ls "ls-files"
  104. # $_gc alias.ls "ls-files -v --full-name"
  105. # $_gc alias.ls "status -u -s ."
  106. $_gc alias.sl "!sl"
  107. # $_gc alias.my-ls "ls-files | xargs ls"
  108. # $_gc alias.ll "!git ls-files | xargs ls -l -CFG --color=auto --time-style=long-iso"
  109. $_gc alias.addi "add -i"
  110. $_gc alias.clean-p "!test -z \"\$(git status -s -uno)\""
  111. $_gc alias.bopen "checkout -b"
  112. $_gc alias.bclose \
  113. "!sh -cx 'git stash && git checkout master && git merge --no-ff -'"
  114. #$_gc alias.wc "!git ls-files -z | xargs -0 wc"
  115. # $_gc push.default "simple"
  116. if $iswindows; then
  117. $_gc core.fileMode false
  118. fi
  119. }
  120. #############################
  121. # gen_tmux_conf_local
  122. setup_tmux(){
  123. tmux_conf_local="$HOME/.tmux.conf.local"
  124. case "`hostname`" in
  125. arch-aspireone)
  126. tmux_bg_color=blue
  127. tmux_fg_color=white
  128. ;;
  129. darwin-mba.local)
  130. tmux_bg_color=cyan
  131. tmux_fg_color=black
  132. ;;
  133. newkiwi)
  134. tmux_bg_color=magenta
  135. tmux_fg_color=white
  136. ;;
  137. freebsd-vb-win7-opti)
  138. tmux_bg_color=red
  139. tmux_fg_color=white
  140. ;;
  141. *)
  142. tmux_bg_color=green
  143. tmux_fg_color=black
  144. ;;
  145. esac
  146. cat <<__EOC__ >"$tmux_conf_local"
  147. # $tmux_conf_local
  148. # Automatically generated by $0
  149. set -g status-right "${USER}@$(hostname) | #(tmux -V) "
  150. set -g status-bg $tmux_bg_color
  151. set -g status-fg $tmux_fg_color
  152. set -g mode-bg $tmux_bg_color
  153. set -g mode-fg $tmux_fg_color
  154. set -g pane-active-border-fg $tmux_bg_color
  155. __EOC__
  156. }
  157. ##############################
  158. # install_scripts
  159. _fetch_script(){
  160. # _fetch_script <url> <binname>
  161. url="$1"
  162. name="$2"
  163. dst="$HOME/.local/bin/$name"
  164. command -v "$name" >/dev/null && return
  165. if _download "$url" "$dst"
  166. then
  167. chmod u+x "$dst"
  168. else
  169. test -f "$dst" && rm -- "$dst"
  170. fi
  171. }
  172. setup_scripts(){
  173. _fetch_script \
  174. https://gist.github.com/10sr/6852317/raw/colortable16.sh colortable16.sh
  175. _fetch_script \
  176. https://gist.github.com/10sr/6852331/raw/256colors2.pl 256colors2.pl
  177. }
  178. ################################
  179. # darwin
  180. __darwin_set_defaults(){
  181. $isdarwin || return 1
  182. # http://appdrill.net/60641/mac-boot-mute.html
  183. #sudo nvram SystemAudioVolume=%80
  184. # add quit entry in menu
  185. defaults write com.apple.finder QuitMenuItem -bool YES
  186. # show full path on titlebar
  187. defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
  188. # do not show desktop icons
  189. defaults write com.apple.finder CreateDesktop -boolean false
  190. killall Finder
  191. # disable dashboard
  192. #defaults write com.apple.dashboard mcx-disabled -bool YES
  193. }
  194. __darwin_start_daemon(){
  195. $isdarwin || return 1
  196. test "`launchctl getenv LC_ALL`" = C || sudo launchctl setenv LC_ALL C
  197. if ! (launchctl list | grep com.apple.locate) >/dev/null
  198. then
  199. sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
  200. fi
  201. }
  202. setup_darwin(){
  203. __darwin_set_defaults
  204. __darwin_start_daemon
  205. }
  206. #########################
  207. # mkdirs
  208. setup_dirs(){
  209. mkdir -p "$__homelocal"
  210. mkdir -p "$__homelocal/bin"
  211. mkdir -p "$__homevar"
  212. }
  213. #########################
  214. # main
  215. main(){
  216. gen_common
  217. . "$__shrc_common"
  218. if test -z "$1"
  219. then
  220. echo "usage: ./setup.sh <setups> ..."
  221. echo "setups: all $__setups"
  222. exit 1
  223. fi
  224. while test -n "$1"
  225. do
  226. if test "$1" = all
  227. then
  228. for c in $__setups
  229. do
  230. set -x
  231. setup_$c
  232. set +x
  233. done
  234. fi
  235. for c in $__setups
  236. do
  237. if test "$1" = "$c"
  238. then
  239. set -x
  240. setup_$c
  241. set +x
  242. fi
  243. done
  244. shift
  245. done
  246. }
  247. main "$@"