瀏覽代碼

Implemented alternative dotfile dirs via mask mechanism

Each mask is appended to DOTROOT to create an alternative DOTROOT path,
and finally to link target.  Therefore, you can have shared structure
like this:

    dotroot/fooapp
    dotroot/barapp
    dotroot.config/janeapp
    dotroot.config/aliceapp
    dotroot.local/share/janeapp
    dotroot.local/share/fooapp

The first two examples work just like before, but if masks ".config" and
".local/share" are defined, the rest is treated specially.  Final
mapping looks like this:

    ~/.fooapp -> dotroot/fooapp
    ~/.barapp -> dotroot/barapp
    ~/.config/aliceapp -> dotroot.config/aliceapp
    ~/.config/janeapp -> dotroot.config/janeapp
    ~/.local/share/fooapp-> dotroot.local/share/fooapp
    ~/.local/share/janeapp -> dotroot.local/share/janeapp

This allows for quite a good flexibility of how you define your shared
structure to reflect habits of many common applications while retaining
ease of deplyment.

Note that:

*   `.config` and `.local/share` masks are defined by default

*   you can provide your own by using one or more `--mask` arguments;
    this, however, removes the default ones

**Warning:** Potential clases between masks like ".local/share and
".local" are **not** solved within script.  Avoid that.  Currently
it's an undefined behavior.
Alois Mahdal 12 年之前
父節點
當前提交
415da606a2
共有 5 個檔案被更改,包括 21 行新增6 行删除
  1. 21
    6
      mklinks
  2. 0
    0
      test_dotfiles.config/aaaconfig
  3. 0
    0
      test_dotfiles.config/bbbconfig
  4. 0
    0
      test_dotfiles.local/share/aaashare
  5. 0
    0
      test_dotfiles.local/share/bbbshare

+ 21
- 6
mklinks 查看文件

@@ -36,12 +36,16 @@ sub usage { print STDERR "usage: $0: DOTROOT [PREFIX]\n"; exit 1; }
36 36
 
37 37
 my $dotroot;
38 38
 my $prefix;
39
+my @masks;
39 40
 
40 41
 my $opts = GetOptions(
41
-    'dotroot=s' =>  \$dotroot,
42
-    'prefix=s' =>   \$prefix
42
+    'dotroot=s' => \$dotroot,
43
+    'prefix=s'  => \$prefix,
44
+    'masks=s'   => \@masks
43 45
 ) or usage;
44 46
 
47
+@masks = @masks ? @masks : qw ( .config .local/share );
48
+
45 49
 $dotroot = $dotroot // shift;
46 50
 $prefix = $prefix // shift;
47 51
 $prefix = $prefix // $ENV{HOME};
@@ -49,13 +53,24 @@ $dotroot or usage;
49 53
 
50 54
 sub mklinks {
51 55
     my $dotroot = shift;
52
-    -d $dotroot or die "not a directory: $dotroot";
56
+    my $mask = shift;
57
+    $dotroot =~ s|/?$||;
58
+    if ($mask) {
59
+        $dotroot .= $mask;
60
+    }
61
+    if (not -d $dotroot) { warn "not a directory: $dotroot\n"; return }
53 62
     my @dirs = `ls $dotroot`;
54 63
     foreach my $dir (@dirs) {
55 64
         chomp $dir;
56 65
         my $source = File::Spec->rel2abs("$dotroot/$dir");
57
-        my $target = "$prefix/.$dir";
58
-        `mkdir -p $prefix`;
66
+        my $target;
67
+        if ($mask) {
68
+            $target = "$prefix/$mask/$dir";
69
+            `mkdir -p $prefix/$mask`;
70
+        } else {
71
+            $target = "$prefix/.$dir";
72
+            `mkdir -p $prefix`;
73
+        }
59 74
         if (-e $target) {
60 75
             warn "target exists: $target\n";
61 76
         } else {
@@ -65,4 +80,4 @@ sub mklinks {
65 80
 }
66 81
 
67 82
 mklinks($dotroot);
68
-
83
+mklinks($dotroot, $_) foreach (@masks);

+ 0
- 0
test_dotfiles.config/aaaconfig 查看文件


+ 0
- 0
test_dotfiles.config/bbbconfig 查看文件


+ 0
- 0
test_dotfiles.local/share/aaashare 查看文件


+ 0
- 0
test_dotfiles.local/share/bbbshare 查看文件