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.

setup.sh 6.5 KiB

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