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

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