1
1
# !/usr/bin/env perl
2
- # use XXX;use YAML;use YAML::Loader;
2
+ use XXX;use YAML;use YAML::Loader;
3
3
# Next line removes site dirs, so we don't pull in non-core modules.
4
4
BEGIN { @INC = grep not (/ \b site/ ), @INC }
5
5
6
+ # TODO:
7
+ # - backup needs to save the .../conf file
8
+
6
9
my $usage = <<'...' ;
7
10
8
- ... - The Unix Dot File Manager
11
+ ... - The Unix Dot File Manager
9
12
10
13
Usage: ... [options] command [command-options]
11
14
12
15
Commands:
13
- backup - Backup all the dot files that would be changed by 'install'.
14
- install - Copy or link all the dot files into your $HOME directory.
15
- -l | --links Use hardlinks (default)
16
- -s | --symlink Use symlinks
17
- -f | --copy Full copy
18
- list - List all the full paths of the files that would be installed.
19
- status - Get change status of all the dot repositories.
20
- conflicts - Show dot files that collide with ones from other repos
21
- update - Fetch changes from all the dot repositories.
22
- upgrade - Do update and then install.
23
- restore - Restore a backup.
24
- remove - DELETE all the dot files in $HOME that would be installed!!!
25
- configure path/to/dots- conf.yaml
26
- ... can configure itself with this command and a conf file.
27
- env - Get input for a shell eval `... env`, useful for scripting.
16
+ backup - Backup all the dot files that would be changed by 'install'.
17
+ install - Copy or link all the dot files into your $HOME directory.
18
+ -l | --links Use hardlinks (default)
19
+ -s | --symlink Use symlinks
20
+ -f | --copy Full copy
21
+ list - List all the full paths of the files that would be installed.
22
+ status - Get change status of all the dot repositories.
23
+ conflicts - Show dot files that collide with ones from other repos.
24
+ update - Fetch changes from all the dot repositories.
25
+ upgrade - Do update and then install.
26
+ restore - Restore a backup.
27
+ remove - DELETE all the dot files in $HOME that would be installed!!!
28
+ conf(igure) conf-file-path | conf-file-url | <stdin>
29
+ - Put content into the .../ conf configuration file.
30
+ env - Get input for a shell eval `... env`, useful for scripting.
28
31
29
32
Options:
30
33
-v --version Print the version and exit.
@@ -66,10 +69,20 @@ my $conf_file = "$root_dir/conf";
66
69
my $config ; # Config hash
67
70
my $timestamp ; # Time stamp
68
71
my $restore_from ; # Directory to restore from
69
- my $input_file ;
72
+ my $conf_path ;
70
73
71
74
my $cli_install_method = ' ' ;
72
75
76
+ my $no_conf_msg = <<"..." ;
77
+ Error: '$conf_file ' does not exist.
78
+
79
+ Run `... conf <path-or-url>` to set it up.
80
+
81
+ You can also copy $root_dir /conf.example to $conf_file
82
+ and edit appropriately.
83
+
84
+ ...
85
+
73
86
TOP: {
74
87
my $class = __PACKAGE__ ;
75
88
$class -> parse_command_line();
80
93
sub parse_command_line {
81
94
my $class = shift ;
82
95
if (@ARGV == 0) {
83
- $command = ' help ' ;
96
+ $command = ' default ' ;
84
97
}
85
98
elsif ($ARGV [0] =~ / ^(-\? |-h|--help)$ / ) {
86
99
$command = ' help' ;
@@ -99,8 +112,7 @@ sub parse_command_line {
99
112
}
100
113
elsif ($ARGV [0] =~ / ^conf(igure)?$ / ) {
101
114
$command = ' configure' ;
102
- $input_file = splice (@ARGV , 1, 1)
103
- or die " configure requires a dots-conf.yaml file" ;
115
+ $conf_path = splice (@ARGV , 1, 1) || ' ' ;
104
116
}
105
117
elsif ($ARGV [0] =~ / ^-/ ) {
106
118
die " Error: '$ARGV [0]' is an invalid option\n " ;
@@ -138,25 +150,24 @@ sub setup {
138
150
my $class = shift ;
139
151
140
152
-d $root_dir or die " Error: $root_dir is not a directory\n " ;
141
- -f $conf_file or die <<"..." ;
142
- Error: $conf_file does not exist.
143
-
144
- You should copy $root_dir /conf.example to $conf_file
145
- and edit appropriately.
146
-
147
- ...
153
+ -f $conf_file or die $no_conf_msg ;
148
154
$config = YAML::Tiny::LoadFile($conf_file );
149
155
150
156
$config -> {dot_paths_base } ||= ' src' ;
151
157
152
- die " Error: 'dot_paths' not defined in $conf_file \n "
153
- unless defined $config -> {dot_paths };
154
- die " Error: 'dot_paths' needs to be a sequence of mappings.\n "
155
- if ref ($config -> {dot_paths }) ne ' ARRAY' or
156
- not (@{$config -> {dot_paths }}) or
157
- grep {ref ne ' HASH' } @{$config -> {dot_paths }};
158
- die " Error: each dot_path entry must have a 'path' value\n "
159
- if grep {not defined $_ -> {path }} @{$config -> {dot_paths }};
158
+ my $dots = $config -> {dots } || $config -> {dot_paths }
159
+ or die " Error: 'dots' not defined in $conf_file \n " ;
160
+ die " Error: 'dots' needs to be a sequence of mappings.\n "
161
+ if ref ($dots ) ne ' ARRAY' or
162
+ not (@$dots ) or
163
+ grep {ref ne ' HASH' } @$dots ;
164
+ die " Error: each dot_path entry must have a 'path' or 'repo' value\n "
165
+ if grep {
166
+ not defined $_ -> {path } and
167
+ not defined $_ -> {repo }
168
+ } @$dots ;
169
+ delete $config -> {dot_paths };
170
+ $config -> {dots } = $dots ;
160
171
161
172
$config -> {auto_backup } =
162
173
not (exists ($config -> {auto_backup })) ? 1 :
@@ -174,6 +185,11 @@ and edit appropriately.
174
185
$timestamp = sprintf " %04d%02d%02d-%02d%02d%02d" , $year , $mon , $day , $hour , $min , $sec ;
175
186
}
176
187
188
+ sub handle_default {
189
+ my $class = shift ;
190
+ $class -> handle_help;
191
+ }
192
+
177
193
sub handle_help {
178
194
my $class = shift ;
179
195
print $usage ;
195
211
196
212
sub handle_configure {
197
213
my $class = shift ;
198
- $config = YAML::Tiny::LoadFile($input_file );
214
+ die " '$conf_file ' already exists\n "
215
+ if -f $conf_file ;
216
+ if (not $conf_path ) {
217
+ my $text = do {local $/ ; <STDIN >};
218
+ open OUT, " >$conf_file " or die " Can't open $conf_file for output" ;
219
+ print OUT $text ;
220
+ close $text ;
221
+ }
222
+ elsif ($conf_path =~ m ! ^https?://! ) {
223
+ $class -> _run_sys(" curl $conf_path > $conf_file " );
224
+ }
225
+ elsif ($conf_path =~ / :/ ) {
226
+ $class -> _run_sys(" scp $conf_path $conf_file " );
227
+ }
228
+ elsif (-f $conf_path ) {
229
+ $class -> _run_sys(" cp $conf_path $conf_file " );
230
+ }
231
+ else {
232
+ die " Unknown argument '$conf_path ' for '... configure'\n " ;
233
+ }
234
+ }
235
+
236
+ sub handle_configure_xxx {
237
+ my $class = shift ;
238
+ $config = YAML::Tiny::LoadFile($conf_path );
199
239
my $array = $class -> _determine_config_section($config )
200
240
or die " Can't determine a config for this environment\n " ;
201
241
my @paths ;
@@ -230,7 +270,7 @@ Created $conf_file
230
270
231
271
Now run this command to install your dot files:
232
272
233
- ~/.../bin/ ... install
273
+ ~/.../... install
234
274
...
235
275
}
236
276
@@ -284,6 +324,7 @@ sub _each_make {
284
324
285
325
sub handle_install {
286
326
my $class = shift ;
327
+ $class -> check_all_paths();
287
328
$class -> handle_backup(' quiet' ) if $config -> {auto_backup };
288
329
$class -> handle_dots_install();
289
330
$class -> handle_dots_deps();
0 commit comments