| 1 |
# Actions entry |
| 2 |
|
| 3 |
The **actions** entry (optional) contains an actions mapping. |
| 4 |
|
| 5 |
```yaml |
| 6 |
actions: |
| 7 |
<action-key>: <command-to-execute> |
| 8 |
``` |
| 9 |
|
| 10 |
*pre* actions: |
| 11 |
```yaml |
| 12 |
actions: |
| 13 |
pre: |
| 14 |
<action-key>: <command-to-execute> |
| 15 |
``` |
| 16 |
|
| 17 |
*post* actions: |
| 18 |
```yaml |
| 19 |
actions: |
| 20 |
post: |
| 21 |
<action-key>: <command-to-execute> |
| 22 |
``` |
| 23 |
|
| 24 |
Actions can be either `post` or `pre`. |
| 25 |
|
| 26 |
* `post` action will be executed after the dotfile deployment. |
| 27 |
* `pre` action will be executed before the dotfile deployment. |
| 28 |
|
| 29 |
If you don't specify either `post` or `pre`, the action will be executed |
| 30 |
after the dotfile deployment (which is equivalent to `post`). |
| 31 |
Actions cannot obviously be named `pre` or `post`. |
| 32 |
|
| 33 |
Four types of actions can be defined: |
| 34 |
|
| 35 |
* [Dotfiles actions](config-dotfiles.md#dotfile-actions) |
| 36 |
* [Default actions](config-config.md#default_actions-entry) |
| 37 |
* [Profile actions](config-profiles.md#profile-actions-entry) |
| 38 |
* [Fake dotfiles and actions](config-actions.md#fake-dotfile-and-actions) |
| 39 |
|
| 40 |
**Notes**: |
| 41 |
|
| 42 |
* Any action with a key starting with an underscore (`_`) won't be shown in output. This can be useful when working with sensitive data containing passwords, for example. |
| 43 |
* Make sure to quote your actions to avoid bad surprises |
| 44 |
* Actions are executed using the default shell (`$SHELL`) |
| 45 |
* To use shell variables in your actions, you need to escape the curly brackets (`${HOME}` becomes `${{HOME}}`) |
| 46 |
|
| 47 |
## Fake dotfile and actions |
| 48 |
|
| 49 |
*Fake* dotfile can be created by specifying no `dst` and no `src` (see [Fake dotfiles and actions](config-actions.md#fake-dotfile-and-actions)). |
| 50 |
By binding an action to such a *fake* dotfile, you make sure the action is always executed since |
| 51 |
*fake* dotfile are always considered installed. |
| 52 |
|
| 53 |
```yaml |
| 54 |
actions: |
| 55 |
always_action: 'date > ~/.dotdrop.log' |
| 56 |
dotfiles: |
| 57 |
fake: |
| 58 |
src: |
| 59 |
dst: |
| 60 |
actions: |
| 61 |
- always_action |
| 62 |
``` |
| 63 |
|
| 64 |
## Dynamic actions |
| 65 |
|
| 66 |
Variables ([config variables and dynvariables](config-file.md#variables) |
| 67 |
and [template variables](../template/template-variables.md)) can be used |
| 68 |
in actions for more advanced use-cases. |
| 69 |
|
| 70 |
Actions accept arguments in the form `{<arg-num>}` which specifies which |
| 71 |
argument to replace in the action. |
| 72 |
|
| 73 |
For example |
| 74 |
```yaml |
| 75 |
dotfiles: |
| 76 |
f_test: |
| 77 |
dst: ~/.test |
| 78 |
src: test |
| 79 |
actions: |
| 80 |
- cookie_mv_somewhere "/tmp/moved-cookie" |
| 81 |
variables: |
| 82 |
cookie_dir_available: (test -d /tmp/cookiedir || mkdir -p /tmp/cookiedir) |
| 83 |
cookie_header: "{{@@ cookie_dir_available @@}} && echo 'header' > /tmp/cookiedir/cookie" |
| 84 |
cookie_mv: "{{@@ cookie_header @@}} && mv /tmp/cookiedir/cookie" |
| 85 |
actions: |
| 86 |
cookie_mv_somewhere: "{{@@ cookie_mv @@}} {0}" |
| 87 |
``` |
| 88 |
|
| 89 |
or even something like this: |
| 90 |
```yaml |
| 91 |
actions: |
| 92 |
log: "echo {0} >> {1}" |
| 93 |
config: |
| 94 |
default_actions: |
| 95 |
- log '{{@@ _dotfile_key @@}} installed' "/tmp/log" |
| 96 |
... |
| 97 |
``` |
| 98 |
|
| 99 |
Make sure to quote the actions using variables. |