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.
 
 
 
 
 
 

243 regels
5.8 KiB

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