Debian Codegraph @

docs/howto/create-special-files.md

raw
1 # Create files on install
2
3 One way to create symlinks (or any other special file) is to use a combination of
4 [actions](../config/config-actions.md) and a *fake* dotfile.
5
6 Let's say, for example, you have a list of directories you want to link
7 from under `~/.original` to `~/symlinks`.
8 ```bash
9 $ tree ~/.original
10 /home/user/.original
11 ├── dir1
12 ├── dir2
13 └── dir3
14 ```
15
16 First you would store these directory names in a text file in your `<dotpath>/links.txt`:
17 ```
18 dir1
19 dir2
20 dir3
21 ```
22
23 The config file would contain different elements:
24
25 * A `dynvariables` that will read the above text file
26 * A few `variables` for the source and destination
27 * An action that will create the destination directory and symlink those directories
28 * A *fake* dotfile (with no `src` and no `dst` values) that will be always installed with the above action
29
30 ```yaml
31 dynvariables:
32 links_list: "cat {{@@ _dotdrop_dotpath @@}}/links.txt | xargs"
33 ...
34 variables:
35 links_dst: "{{@@ env['HOME'] @@}}/.symlinks"
36 links_src: "{{@@ env['HOME'] @@}}/.original"
37 ...
38 actions:
39 symlink_them: 'mkdir -p "{1}" && for lnk in {0}; do ln -s "{{@@ links_src @@}}/$lnk" "{1}/$lnk"; done'
40 ...
41 fake:
42 src:
43 dst:
44 actions:
45 - symlink_them '{{@@ links_list @@}}' '{{@@ links_dst @@}}'
46 ```
47
48 The result would be:
49 ```bash
50 $ tree ~/.symlinks
51 /home/user/.symlinks
52 ├── dir1 -> /home/user/.original/dir1
53 ├── dir2 -> /home/user/.original/dir2
54 └── dir3 -> /home/user/.original/dir3
55 ```
56
57 For reference, see [issue 243](https://github.com/deadc0de6/dotdrop/issues/243).