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 5.9 KiB

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