Last active
February 17, 2025 22:11
-
-
Save smeech/a11b09c48aa2cae518bab76c996f6198 to your computer and use it in GitHub Desktop.
[Swap outputs] The following snippet produces a choice Form and then uses a shell or Python script to swap its input for different values. It's an alternative to label: & id: use, that enables the use of the choice: drop-down facility #espanso #bash #python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The following snippet produces a choice Form and then uses | |
| # a shell script to swap its input for different values. | |
| # It's an alternative to label: & id: use, that | |
| # enables the use of the choice: drop-down facility | |
| - trigger: :test | |
| replace: "{{output}}" | |
| vars: | |
| - name: form1 | |
| type: form | |
| params: | |
| layout: "[[choices]]" | |
| fields: | |
| choices: | |
| type: choice | |
| values: | | |
| one | |
| two | |
| three | |
| default: one | |
| - name: output | |
| type: shell | |
| params: | |
| shell: bash | |
| cmd: | | |
| case $"{{form1.choices}}" in | |
| one) | |
| output=four ;; | |
| two) | |
| output=five ;; | |
| three) | |
| output=six ;; | |
| esac | |
| echo $output | |
| # For Python, replace the "output" block with: | |
| - name: output | |
| type: script | |
| params: | |
| args: | |
| - python | |
| - -c | |
| - | | |
| choices = { | |
| "one": "four", | |
| "two": "five", | |
| "three": "six" | |
| } | |
| print(choices.get("{{form1.choices}}", "")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment