From 946675f11cf88b2f2af544df62e8ce1d1fbdd576 Mon Sep 17 00:00:00 2001 From: smeech Date: Fri, 13 Dec 2024 14:17:22 +0000 Subject: [PATCH 1/6] Form URL list Much amended version of part of the failed PR https://github.com/espanso/hub/pull/87. It's been over a year since the original submission and I have been unable to get a response from @mistahBen, even going as far as submitting a PR https://github.com/mistahBen/espanso_hub/pull/1 to his own repo. I like this package as it illustrates a useful technique, so I think it's worth preserving. Thanks to @mistahBen for the idea! --- packages/form-list/0.2.0/README.md | 19 +++++++++++ packages/form-list/0.2.0/_manifest.yml | 7 ++++ packages/form-list/0.2.0/form_urls.csv | 2 ++ packages/form-list/0.2.0/package.yml | 47 ++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 packages/form-list/0.2.0/README.md create mode 100644 packages/form-list/0.2.0/_manifest.yml create mode 100644 packages/form-list/0.2.0/form_urls.csv create mode 100644 packages/form-list/0.2.0/package.yml diff --git a/packages/form-list/0.2.0/README.md b/packages/form-list/0.2.0/README.md new file mode 100644 index 0000000..0094209 --- /dev/null +++ b/packages/form-list/0.2.0/README.md @@ -0,0 +1,19 @@ +# Form list +## A package for getting a list of expansions from one form via a CSV list. + +# Setup +The `package.yml` does not need to be edited. + +You will need to edit the entries in the `form_urls.csv`. The sample lines are a good starting point. The basic syntax is: + +| Name/description (without quotes) | URL | +| --- | --- | +| gmail | https://gmail.com/ | + +**Separate the two fields with a comma.** Remember to save the file! + +## 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. \ No newline at end of file diff --git a/packages/form-list/0.2.0/_manifest.yml b/packages/form-list/0.2.0/_manifest.yml new file mode 100644 index 0000000..ee21105 --- /dev/null +++ b/packages/form-list/0.2.0/_manifest.yml @@ -0,0 +1,7 @@ +name: "form-list" +title: "Form URLs List" +description: Uses a CSV to present a list of links and then pastes the chosen URL. +version: 0.2.0 +author: Ben Alexander (mistahben), contributions Stephen Meech (smeech) +tags: ["utility", "internet", "URL", "CSV", "forms"] +homepage: https://github.com/Various-forks/mistahBen_espanso_hub \ No newline at end of file diff --git a/packages/form-list/0.2.0/form_urls.csv b/packages/form-list/0.2.0/form_urls.csv new file mode 100644 index 0000000..82b3a03 --- /dev/null +++ b/packages/form-list/0.2.0/form_urls.csv @@ -0,0 +1,2 @@ +Espanso documentation, https://espanso.org/docs/ +DuckDuckGo, https://duckduckgo.com \ No newline at end of file diff --git a/packages/form-list/0.2.0/package.yml b/packages/form-list/0.2.0/package.yml new file mode 100644 index 0000000..dd7e6e3 --- /dev/null +++ b/packages/form-list/0.2.0/package.yml @@ -0,0 +1,47 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/espanso/espanso/dev/schemas/match.schema.json + +global_vars: + - name: urlcsv + type: shell + params: + cmd: echo "$CONFIG/match/packages/form-list/0.2.0/form_urls.csv" + +matches: + - trigger: :forms + replace: '{{form_url}}' + vars: + - name: form_names + type: script + params: + args: + - python + - -c + - | + import csv + with open('{{urlcsv}}', newline='') as f: + for row in csv.reader(f): print(row[0]) + - name: choice + type: form + params: + layout: | + Get link to D65 form: + [[choices]] + fields: + choices: + type: list + values: '{{form_names}}' + - name: form_url + type: script + params: + args: + - python + - -c + - | + import csv + with open('{{urlcsv}}', newline='') as f: + for row in csv.reader(f): + if row[0] == '{{choice.choices}}': + print(row[1]) + break + + From 3714943cc65f19b28425cf1e1c31e8d53b44e152 Mon Sep 17 00:00:00 2001 From: smeech Date: Fri, 13 Dec 2024 16:42:13 +0000 Subject: [PATCH 2/6] OS-agnotic changes Add OS-agnostic code to derive path to CSV file. --- packages/form-list/0.2.0/README.md | 4 ++-- packages/form-list/0.2.0/package.yml | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/form-list/0.2.0/README.md b/packages/form-list/0.2.0/README.md index 0094209..a2a0344 100644 --- a/packages/form-list/0.2.0/README.md +++ b/packages/form-list/0.2.0/README.md @@ -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. \ No newline at end of file +Requires Python, but if present should work in all operating systems. \ No newline at end of file diff --git a/packages/form-list/0.2.0/package.yml b/packages/form-list/0.2.0/package.yml index dd7e6e3..a6f2c7e 100644 --- a/packages/form-list/0.2.0/package.yml +++ b/packages/form-list/0.2.0/package.yml @@ -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: @@ -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 @@ -30,6 +38,7 @@ matches: choices: type: list values: '{{form_names}}' + # Return paired item as selected above - name: form_url type: script params: @@ -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]) From fbfae7f99521e15e0ee02665a6696519a905449a Mon Sep 17 00:00:00 2001 From: Stephen Meech Date: Fri, 13 Dec 2024 16:43:44 +0000 Subject: [PATCH 3/6] Update package.yml Spelling --- packages/form-list/0.2.0/package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/form-list/0.2.0/package.yml b/packages/form-list/0.2.0/package.yml index a6f2c7e..3927299 100644 --- a/packages/form-list/0.2.0/package.yml +++ b/packages/form-list/0.2.0/package.yml @@ -17,7 +17,7 @@ matches: - trigger: :forms replace: '{{form_url}}' vars: - # Read choice-list options from CVS file. + # Read choice-list options from CSV file. - name: form_names type: script params: From ad70abf8d2e57580243aee4f5cab28f85b332172 Mon Sep 17 00:00:00 2001 From: smeech Date: Fri, 13 Dec 2024 17:02:32 +0000 Subject: [PATCH 4/6] Minor updates --- packages/form-list/0.2.0/README.md | 2 +- packages/form-list/0.2.0/package.yml | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/form-list/0.2.0/README.md b/packages/form-list/0.2.0/README.md index a2a0344..a56c8fa 100644 --- a/packages/form-list/0.2.0/README.md +++ b/packages/form-list/0.2.0/README.md @@ -10,7 +10,7 @@ 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! Ensure you retain its UTF-8 encoding. Some spreadsheet programs will switch to UTF-8-BOM. +**Separate the two fields with a comma.** Remember to save the file! Ensure you retain its UTF-8 encoding - spreadsheet programs may switch to UTF-8-BOM. ## Reuse diff --git a/packages/form-list/0.2.0/package.yml b/packages/form-list/0.2.0/package.yml index 3927299..4a7525b 100644 --- a/packages/form-list/0.2.0/package.yml +++ b/packages/form-list/0.2.0/package.yml @@ -28,11 +28,12 @@ matches: import csv with open(r'{{urlcsv}}', newline='') as f: for row in csv.reader(f): print(row[0]) + # Form - name: choice type: form params: layout: | - Get link to D65 form: + Get link for: [[choices]] fields: choices: @@ -50,7 +51,4 @@ matches: with open(r'{{urlcsv}}', newline='') as f: for row in csv.reader(f): if row[0] == '{{choice.choices}}': - print(row[1]) - break - - + print(row[1]) ; break From 1b6cebd3afa44e4cd0102115b3088057843411e0 Mon Sep 17 00:00:00 2001 From: Stephen Meech Date: Fri, 13 Dec 2024 17:28:07 +0000 Subject: [PATCH 5/6] Update _manifest.yml --- packages/form-list/0.2.0/_manifest.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/form-list/0.2.0/_manifest.yml b/packages/form-list/0.2.0/_manifest.yml index ee21105..3876a57 100644 --- a/packages/form-list/0.2.0/_manifest.yml +++ b/packages/form-list/0.2.0/_manifest.yml @@ -2,6 +2,6 @@ name: "form-list" title: "Form URLs List" description: Uses a CSV to present a list of links and then pastes the chosen URL. version: 0.2.0 -author: Ben Alexander (mistahben), contributions Stephen Meech (smeech) +author: Ben Alexander (mistahBen), updated by Stephen Meech (smeech) tags: ["utility", "internet", "URL", "CSV", "forms"] -homepage: https://github.com/Various-forks/mistahBen_espanso_hub \ No newline at end of file +homepage: https://github.com/Various-forks/mistahBen_espanso_hub From 9489f0037561192c405881f3ba367179761163d5 Mon Sep 17 00:00:00 2001 From: Stephen Meech Date: Fri, 13 Dec 2024 17:34:03 +0000 Subject: [PATCH 6/6] Update _manifest.yml --- packages/form-list/0.2.0/_manifest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/form-list/0.2.0/_manifest.yml b/packages/form-list/0.2.0/_manifest.yml index 3876a57..a60a326 100644 --- a/packages/form-list/0.2.0/_manifest.yml +++ b/packages/form-list/0.2.0/_manifest.yml @@ -4,4 +4,4 @@ description: Uses a CSV to present a list of links and then pastes the chosen UR version: 0.2.0 author: Ben Alexander (mistahBen), updated by Stephen Meech (smeech) tags: ["utility", "internet", "URL", "CSV", "forms"] -homepage: https://github.com/Various-forks/mistahBen_espanso_hub +homepage: https://github.com/smeech