Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

setup.sh 7.5 KiB

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