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.

setup.sh 6.7 KiB

11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. *)
  138. tmux_bg_color=green
  139. tmux_fg_color=black
  140. ;;
  141. esac
  142. cat <<__EOC__ >"$tmux_conf_local"
  143. # $tmux_conf_local
  144. # Automatically generated by $0
  145. set -g status-right "${USER}@$(hostname) | #(tmux -V) "
  146. set -g status-bg $tmux_bg_color
  147. set -g status-fg $tmux_fg_color
  148. set -g mode-bg $tmux_bg_color
  149. set -g mode-fg $tmux_fg_color
  150. set -g pane-active-border-fg $tmux_bg_color
  151. __EOC__
  152. }
  153. ##############################
  154. # install_scripts
  155. _fetch_script(){
  156. # _fetch_script <url> <binname>
  157. url="$1"
  158. name="$2"
  159. dst="$HOME/.local/bin/$name"
  160. command -v "$name" >/dev/null && return
  161. if _download "$url" "$dst"
  162. then
  163. chmod u+x "$dst"
  164. else
  165. test -f "$dst" && rm -- "$dst"
  166. fi
  167. }
  168. setup_scripts(){
  169. _fetch_script \
  170. https://gist.github.com/10sr/6852317/raw/colortable16.sh colortable16.sh
  171. _fetch_script \
  172. https://gist.github.com/10sr/6852331/raw/256colors2.pl 256colors2.pl
  173. }
  174. ################################
  175. # darwin
  176. __darwin_set_defaults(){
  177. $isdarwin || return 1
  178. # http://appdrill.net/60641/mac-boot-mute.html
  179. #sudo nvram SystemAudioVolume=%80
  180. # add quit entry in menu
  181. defaults write com.apple.finder QuitMenuItem -bool YES
  182. # show full path on titlebar
  183. defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
  184. # do not show desktop icons
  185. defaults write com.apple.finder CreateDesktop -boolean false
  186. killall Finder
  187. # disable dashboard
  188. #defaults write com.apple.dashboard mcx-disabled -bool YES
  189. }
  190. __darwin_start_daemon(){
  191. $isdarwin || return 1
  192. test "`launchctl getenv LC_ALL`" = C || sudo launchctl setenv LC_ALL C
  193. if ! (launchctl list | grep com.apple.locate) >/dev/null
  194. then
  195. sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
  196. fi
  197. }
  198. setup_darwin(){
  199. __darwin_set_defaults
  200. __darwin_start_daemon
  201. }
  202. #########################
  203. # mkdirs
  204. setup_dirs(){
  205. mkdir -p "$__homelocal"
  206. mkdir -p "$__homelocal/bin"
  207. mkdir -p "$__homevar"
  208. }
  209. #########################
  210. # main
  211. main(){
  212. gen_common
  213. . "$__shrc_common"
  214. if test -z "$1"
  215. then
  216. echo "usage: ./setup.sh <setups> ..."
  217. echo "setups: all $__setups"
  218. exit 1
  219. fi
  220. while test -n "$1"
  221. do
  222. if test "$1" = all
  223. then
  224. for c in $__setups
  225. do
  226. set -x
  227. setup_$c
  228. set +x
  229. done
  230. fi
  231. for c in $__setups
  232. do
  233. if test "$1" = "$c"
  234. then
  235. set -x
  236. setup_$c
  237. set +x
  238. fi
  239. done
  240. shift
  241. done
  242. }
  243. main "$@"