Debian Codegraph @

docs/howto/append.md

raw
1 # Append text on install
2
3 Sometimes it might be useful to be able to append some text to a
4 file. Dotdrop is able to do that with the help of
5 [actions](../config/config-actions.md) and a temporary file.
6
7 Below is a config example to append to a file:
8 ```yaml
9 dynvariables:
10 tmpfile: mktemp
11 variables:
12 somefile_final: ~/.somefile
13 dotfiles:
14 f_somefile:
15 dst: "{{@@ tmpfile @@}}"
16 src: somefile
17 actions:
18 - strip "{{@@ somefile_final @@}}"
19 - append "{{@@ tmpfile @@}}" "{{@@ somefile_final @@}}"
20 actions:
21 pre:
22 strip: "sed -i '/^# my pattern$/,$d' {0}"
23 post:
24 append: "cat {0} >> {1}; rm -f {0}"
25 ```
26 During installation, the `strip` action is executed before the installation, and it strips everything from the pattern `# my pattern` to the end of the file. Then the dotfile `somefile` is installed in a temporary location (here `tmpfile`) and finally the post action `append` will append the contents of the `tmpfile` to the final dotfile pointed to by `somefile_final`.
27
28 Obviously, the dotfile in the dotpath should start with a unique pattern (here `# my pattern`):
29 ```
30 # my pattern
31 this is the end
32 ```