Skip to content

Commit

Permalink
OS-agnotic changes
Browse files Browse the repository at this point in the history
Add OS-agnostic code to derive path to CSV file.
  • Loading branch information
smeech committed Dec 13, 2024
1 parent 946675f commit 3714943
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/form-list/0.2.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ You will need to edit the entries in the `form_urls.csv`. The sample lines are a
| --- | --- |
| gmail | https://gmail.com/ |

**Separate the two fields with a comma.** Remember to save the file!
**Separate the two fields with a comma.** Remember to save the file! Ensure you retain its UTF-8 encoding. Some spreadsheet programs will switch to UTF-8-BOM.

## Reuse

You can of course also copy the contents of this package and create multiple form lists with other text. 👍 If you do so, you will need to edit the global variable for the location of the csv file.

Requires Python, but if present should work in all OSs.
Requires Python, but if present should work in all operating systems.
19 changes: 14 additions & 5 deletions packages/form-list/0.2.0/package.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/espanso/espanso/dev/schemas/match.schema.json

global_vars:
# OS-agnostic derivation of path to CSV file.
- name: urlcsv
type: shell
type: script
params:
cmd: echo "$CONFIG/match/packages/form-list/0.2.0/form_urls.csv"

args:
- python
- -c
- |
import os
config_path = os.getenv("CONFIG")
print(os.path.join(config_path, "match", "packages", "form-list", "0.2.0", "form_urls.csv"))
matches:
- trigger: :forms
replace: '{{form_url}}'
vars:
# Read choice-list options from CVS file.
- name: form_names
type: script
params:
Expand All @@ -18,7 +26,7 @@ matches:
- -c
- |
import csv
with open('{{urlcsv}}', newline='') as f:
with open(r'{{urlcsv}}', newline='') as f:
for row in csv.reader(f): print(row[0])
- name: choice
type: form
Expand All @@ -30,6 +38,7 @@ matches:
choices:
type: list
values: '{{form_names}}'
# Return paired item as selected above
- name: form_url
type: script
params:
Expand All @@ -38,7 +47,7 @@ matches:
- -c
- |
import csv
with open('{{urlcsv}}', newline='') as f:
with open(r'{{urlcsv}}', newline='') as f:
for row in csv.reader(f):
if row[0] == '{{choice.choices}}':
print(row[1])
Expand Down

0 comments on commit 3714943

Please sign in to comment.