initial
[zsh.git] / .zsh / install.zsh
1 # -*- sh -*-
2
3 autoload colors ; colors
4
5 # Install or update my ZSH config on a remote host.
6 # Needs Git and makeself locally
7 install-zsh() {
8 local remote
9 local work
10 local start
11 remote=$1
12 work=$(mktemp -d)
13 start=$(pwd)
14 {
15 local OK="$fg_bold[green]OK.${reset_color}"
16 print -n "$fg[green]Building archive...${reset_color} "
17 cd $ZSH
18 git archive HEAD | tar -C $work -xf -
19 mkdir -p $work/zsh-syntax-highlighting
20 cd $ZSH/zsh-syntax-highlighting
21 git archive HEAD | tar -C $work/zsh-syntax-highlighting -xf -
22 cp $HOME/.zshenv $work/zshenv.home
23 print $OK
24 print -n "$fg[green]Building installer...${reset_color} "
25 makeself --gzip $work $ZSH/zsh-install.sh \
26 "$USER ZSH config files" zsh ./install.zsh MAGIC
27 print $OK
28 [[ -z $1 ]] || {
29 print "$fg[green]Remote install...${reset_color} "
30 scp $ZSH/zsh-install.sh ${remote}:
31 ssh $remote sh ./zsh-install.sh
32 print $OK
33 }
34 } always {
35 rm -rf $work
36 cd $start
37 }
38 }
39
40 # We can be executed to install ourself to the final destination
41 if [[ $1 == "MAGIC" ]]; then
42 (( $+commands[rsync] )) || {
43 print "$fg_bold[red]rsync not found, install it${reset_color}"
44 exit 2
45 }
46 local OK="$fg[green]OK.${reset_color}"
47
48 # Migrate history
49 print -n "$fg[green]History migration...${reset_color} "
50 mkdir -p ~/.zsh/var/dirhist
51 mkdir -p ~/.zsh/.zcompcache
52 { mv ~/.zsh_history ~/.zsh/var/history.$USER.$HOST } 2> /dev/null
53 print $OK
54 print "$fg[green]Installation of zsh files...${reset_color} "
55 rsync -rlp --exclude=var/ --exclude=.zcompcache/ --delete . ~/.zsh/.
56 rm -f ~/.zlogin
57 rm -f ~/.zlogout
58 rm -f ~/.zshrc
59 rm -f ~/.zshenv
60 ln -s .zsh/zshenv.home ~/.zshenv
61 print $OK
62 fi