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.4 KiB

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