Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

209 Zeilen
5.1 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. 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. # install_scripts
  45. _download(){
  46. # download <url> <file>
  47. if type wget >/dev/null 2>&1
  48. then
  49. wget $__my_wget_options "$1" -O "$2"
  50. elif type curl >/dev/null 2>&1
  51. then
  52. curl --url "$1" --output "$2"
  53. fi
  54. }
  55. _fetch_script(){
  56. # _fetch_script <url> <binname>
  57. url="$1"
  58. name="$2"
  59. dst="$HOME/.local/bin/$name"
  60. command -v "$name" >/dev/null && return
  61. if __download "$url" "$dst"
  62. then
  63. chmod u+x "$dst"
  64. else
  65. test -f "$dst" && rm -- "$dst"
  66. fi
  67. }
  68. install_scripts(){
  69. _fetch_script \
  70. https://gist.github.com/10sr/6852317/raw/colortable16.sh colortable16.sh
  71. _fetch_script \
  72. https://gist.github.com/10sr/6852331/raw/256colors2.pl 256colors2.pl
  73. }
  74. ################################
  75. # darwin_set_defaults
  76. darwin_set_defaults(){
  77. $isdarwin || return 1
  78. # http://appdrill.net/60641/mac-boot-mute.html
  79. #sudo nvram SystemAudioVolume=%80
  80. # add quit entry in menu
  81. defaults write com.apple.finder QuitMenuItem -bool YES
  82. # show full path on titlebar
  83. defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
  84. # do not show desktop icons
  85. defaults write com.apple.finder CreateDesktop -boolean false
  86. killall Finder
  87. # disable dashboard
  88. #defaults write com.apple.dashboard mcx-disabled -bool YES
  89. }
  90. ################################
  91. # darwin_start_daemon
  92. darwin_start_daemon(){
  93. $isdarwin || return 1
  94. test "`launchctl getenv LC_ALL`" = C || sudo launchctl setenv LC_ALL C
  95. if ! (launchctl list | grep com.apple.locate) >/dev/null
  96. then
  97. sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
  98. fi
  99. }
  100. ################################
  101. # git_configs
  102. git_configs(){
  103. if ! command -v git >/dev/null
  104. then
  105. echo "git not found"
  106. return 1
  107. fi
  108. _gitconfig="git config --global"
  109. $_gitconfig user.name '10sr'
  110. $_gitconfig user.email '8slashes+git@gmail.com'
  111. $_gitconfig core.autocrlf false
  112. $_gitconfig core.excludesfile '~/.gitignore'
  113. $_gitconfig color.ui auto
  114. $_gitconfig status.relativePaths false
  115. $_gitconfig status.showUntrackedFiles normal
  116. $_gitconfig log.date iso
  117. command -v xz >/dev/null && \
  118. $_gitconfig tar.txz.command "xz -c"
  119. $_gitconfig push.default current
  120. $_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"
  121. $_gitconfig alias.st "status -s -b"
  122. $_gitconfig alias.b "branch"
  123. $_gitconfig alias.sb "show-branch"
  124. $_gitconfig alias.ci "commit --verbose"
  125. $_gitconfig alias.co "checkout"
  126. $_gitconfig alias.cim "commit --verbose -m"
  127. $_gitconfig alias.di "diff --color"
  128. $_gitconfig alias.me "merge --no-ff --stat -v"
  129. $_gitconfig alias.gr "grep -n"
  130. $_gitconfig alias.ls "ls-files"
  131. # $_gitconfig alias.ls "ls-files -v --full-name"
  132. # $_gitconfig alias.ls "status -u -s ."
  133. $_gitconfig alias.sl "!sl"
  134. # $_gitconfig alias.my-ls "ls-files | xargs ls"
  135. # $_gitconfig alias.ll "!git ls-files | xargs ls -l -CFG --color=auto --time-style=long-iso"
  136. $_gitconfig alias.addi "add -i"
  137. $_gitconfig alias.clean-p "!test -z \"\$(git status -s -uno)\""
  138. $_gitconfig alias.bopen "checkout -b"
  139. $_gitconfig alias.bclose \
  140. "!sh -cx 'git stash && git checkout master && git merge --no-ff -'"
  141. #$_gitconfig alias.wc "!git ls-files -z | xargs -0 wc"
  142. # $_gitconfig push.default "simple"
  143. if $iswindows; then
  144. $_gitconfig core.fileMode false
  145. fi
  146. }
  147. #########################
  148. # mkdirs
  149. mkdirs(){
  150. install -d "$__homelocal"
  151. install -d "$__homelocal/bin"
  152. install -d "$__homevar"
  153. }
  154. #########################
  155. # main
  156. main(){
  157. set -x
  158. gen_common
  159. . "$__shrc_common"
  160. mkdirs
  161. install_scripts
  162. git_configs
  163. if $isdarwin
  164. then
  165. darwin_set_defaults
  166. darwin_start_daemon
  167. fi
  168. set +x
  169. }
  170. main "$@"