Skip to content

Instantly share code, notes, and snippets.

@smeech
Last active February 17, 2025 22:11
Show Gist options
  • Select an option

  • Save smeech/a11b09c48aa2cae518bab76c996f6198 to your computer and use it in GitHub Desktop.

Select an option

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
# 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