Dewifile 1.81 KB
Newer Older
1 2
# -*- cperl -*-

Frank Terbeck's avatar
Frank Terbeck committed
3 4 5
#set_opt 'debug', 'true';
#set_opt 'verbose', 'true';
#set_opt 'dryrun', 'true';
6

7 8 9 10
register '--symlink', 'zshrc';
register '--symlink', 'zshenv';
register '--symlink', 'zlogout';
register '--symlink', 'dircolors';
11

12
register { glob        => 'functions/[_a-zA-Z0-9]*[a-z0-9]',
Frank Terbeck's avatar
Frank Terbeck committed
13 14
           method      => 'symlink',
           destination => '~/.zfunctions' };
15

16 17 18
sub zsh_byte_compile {
    my (@cmd, $old_dir);

19
    print qq{Byte-compiling shell code...\n};
20 21
    $old_dir = getcwd();
    push @cmd, q{zsh}, q{-fc};
22
    push @cmd, q{for i in .zshrc; do
23
                     [[ $i.zwc -nt $i ]] && continue
24
                     printf '  ..compiling %s\n' $i
25
                     zcompile -R -U $i
26 27 28
                 done
                 setopt extended_glob
                 cd .zfunctions &&
29
                 for i in **/*~*(.zwc|~)(-.); do
30
                     [[ $i.zwc -nt $i ]] && continue
31
                     printf '  ..compiling functions/%s\n' $i
32
                     zcompile -R -U $i
33
                 done};
34
    chdir($ENV{HOME}) or early_exit "Couldn't chdir($ENV{HOME}): $!";
35
    system(@cmd);
36
    chdir $old_dir or early_exit "Couldn't chdir($old_dir): $!";
37 38
}

39 40 41 42
sub zsh_upgrade_setup {
    my $old_dir = $ENV{HOME} . "/.zshrc.d";
    if (-d $old_dir) {
        print qq{Removing old split setup directory: $old_dir\n};
43
        system( (q{rm}, q{-rf}, $old_dir) );
44
    }
45 46 47 48 49 50 51
    foreach my $name ( qw{ real real.zwc pre3 pre3.zwc }) {
        my $file = $ENV{HOME} . "/.zshrc.$name";
        if (-e $file || -l $file) {
            print qq{Removing old setup file: $file\n};
            unlink $file;
        }
    }
52 53 54 55 56 57
}

add_hook { type  => 'perl',
           event => 'pre-deploy',
           code  => \&zsh_upgrade_setup };

58 59 60 61
add_hook { type => 'perl',
           event => 'post-deploy',
           code => \&zsh_byte_compile };

Frank Terbeck's avatar
Frank Terbeck committed
62
end