bf1fea509ecf75e049a5c4e03fc816c8c522772a
[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 if [[ -f ~/.zsh_history ]] && [[ ! -f ~/.zsh/var/history.$USER.$HOST ]]; then
52 { mv ~/.zsh_history ~/.zsh/var/history.$USER.$HOST }
53 fi
54 print $OK
55 print -n "$fg[green]HMoving completion dump...${reset_color} "
56 mkdir -p ~/.zsh/.zcompcache
57 for file in ~/.zcompdump ~/.zsh/.zcompdump; do
58 if [[ -f $file ]]; then
59 mv $file ~/.zsh/var/.zcompdump
60 fi
61 done
62 print $OK
63 print "$fg[green]Installation of zsh files...${reset_color} "
64 rsync -rlp --exclude=var/ --exclude=.zcompcache/ --delete . ~/.zsh/.
65 rm -f ~/.zlogin
66 rm -f ~/.zlogout
67 rm -f ~/.zshrc
68 rm -f ~/.zshenv
69 ln -s .zsh/zshenv.home ~/.zshenv
70 print $OK
71 print "$fg[green]Disabling old udh cronjob...${reset_color} "
72 crontab -l|sed -e 's_\(#\?[0-9][0-9] [/6*]* \* \* \* $HOME/bin/udh >/dev/null\)_#off#\1_'|crontab
73 print $OK
74 fi