@@ -16,6 +16,8 @@ Commands:
16
16
17
17
list - List all the full paths of the files that would be installed.
18
18
19
+ status - Get change status of all the dot repositories.
20
+
19
21
update - Fetch changes from all the dot repositories.
20
22
21
23
upgrade - Do update and then install.
@@ -57,6 +59,7 @@ my $root_dir; # ~/.../
57
59
my $conf_file ; # ~/.../conf
58
60
my $config ; # Config hash
59
61
my $timestamp ; # Time stamp
62
+ my $restore_from ; # Directory to restore from
60
63
61
64
TOP: {
62
65
my $class = __PACKAGE__ ;
@@ -81,6 +84,10 @@ sub parse_command_line {
81
84
}
82
85
else {
83
86
$command = $ARGV [0];
87
+ if ($command eq ' restore' ) {
88
+ $restore_from = splice @ARGV , 1, 1
89
+ or die " Error: 'restore' command requires a backup directory argument" ;
90
+ }
84
91
}
85
92
if (@ARGV > 1) {
86
93
die " Error: invalid usage. Try: '... -h'.\n " ;
@@ -148,7 +155,7 @@ sub handle_backup {
148
155
my $quiet = shift or 0;
149
156
my $backup_dir = " $root_dir /backup/$timestamp " ;
150
157
my $backup_list_file = " $root_dir /tmp/$timestamp -backup-list" ;
151
- print " Backing up your dot files: \n " ;
158
+ print " Backing up your dot files to $backup_dir / \n " ;
152
159
open F, " > $backup_list_file " ;
153
160
my $n = 0;
154
161
for my $file (sort keys %{$class -> _all_files}) {
@@ -207,21 +214,39 @@ sub handle_list {
207
214
208
215
sub handle_update {
209
216
my $class = shift ;
210
- die " Error: 'update' command not yet implemented\n " ;
217
+ print " Updating your `...` system and dot files:\n " ;
218
+ for my $dir ($root_dir , $class -> _all_dot_paths) {
219
+ next unless -d " $dir /.git" ;
220
+ my $cmd = " (cd $dir ; git pull)" ;
221
+ $class -> _run_sys($cmd );
222
+ }
223
+ }
224
+
225
+ sub handle_status {
226
+ my $class = shift ;
227
+ for my $dir ($root_dir , $class -> _all_dot_paths) {
228
+ next unless -d " $dir /.git" ;
229
+ my $cmd = " (cd $dir ; git status)" ;
230
+ $class -> _run_sys($cmd );
231
+ }
211
232
}
212
233
213
234
sub handle_upgrade {
214
235
my $class = shift ;
215
- die " Error: 'upgrade' command not yet implemented\n " ;
216
- print " Updating your `...` system and dot files:\n " ;
217
236
$class -> handle_update;
218
237
$class -> handle_install;
219
238
}
220
239
221
240
sub handle_restore {
222
241
my $class = shift ;
242
+ die " '$restore_from ' is not a backup directory"
243
+ unless -d $restore_from ;
244
+
223
245
$class -> handle_backup(' quiet' ) if $config -> {auto_backup };
224
- die " Error: 'restore' command not yet implemented\n " ;
246
+ print " Restoring your dot files from $restore_from \n " ;
247
+ my $cmd = " (cd $restore_from ; find . | cpio -dump $home_dir )" ;
248
+ $class -> _run_sys($cmd );
249
+ print " Restore complete.\n " ;
225
250
}
226
251
227
252
sub handle_remove {
@@ -231,9 +256,12 @@ sub handle_remove {
231
256
my $all_files = $class -> _all_files;
232
257
my $n = 0;
233
258
for my $file (sort keys %$all_files ) {
234
- my $cmd = " unlink $file " ;
259
+ my $cmd = " rm -f $file " ;
235
260
$class -> _run_sys($cmd );
236
- $n ++; } print " Deleted $n dot files\n " ; }
261
+ $n ++;
262
+ }
263
+ print " Deleted $n dot files\n " ;
264
+ }
237
265
238
266
sub _run_sys {
239
267
my $class = shift ;
@@ -260,9 +288,9 @@ sub _up_to_date {
260
288
return <S> eq <D>;
261
289
}
262
290
263
- sub _all_files {
291
+ sub _all_dot_paths {
264
292
my $class = shift ;
265
- my $all_files = {} ;
293
+ my @paths ;
266
294
for my $entry (@{$config -> {dot_paths }}) {
267
295
my $path = $entry -> {path };
268
296
if ($path !~ / ^\/ / ) {
@@ -275,6 +303,15 @@ sub _all_files {
275
303
unless $path =~ / ^\/ / ;
276
304
die " Error: '$path ' is not a directory\n "
277
305
unless -d $path ;
306
+ push @paths , $path ;
307
+ }
308
+ return @paths ;
309
+ }
310
+
311
+ sub _all_files {
312
+ my $class = shift ;
313
+ my $all_files = {};
314
+ for my $path ($class -> _all_dot_paths) {
278
315
for my $file (` (cd $path ; find . -type f)` ) {
279
316
$file =~ s ! ^\. /!! ;
280
317
chomp ($file );
0 commit comments