Skip to content

Commit

Permalink
WIP: add ability to customize refformat
Browse files Browse the repository at this point in the history
This feature is still in development, and is being put on the backburner
for now due to limitations of Alfred 5.5's Text View. For more details,
see:
<https://www.alfredforum.com/topic/21708-pre-populating-a-text-views-script-input-field-with-an-initial-value/>
  • Loading branch information
caleb531 committed Apr 9, 2024
1 parent efda391 commit 04ac2d8
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
Binary file modified YouVersion Suggest (Alfred 5).alfredworkflow
Binary file not shown.
1 change: 0 additions & 1 deletion tests/test_filter_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def test_show_current_refformat(self):
self.assertEqual(len(results), 1)
self.assertEqual(results[0]["uid"], "yvs-refformat-Z {content}")
self.assertEqual(results[0]["title"], "Z Jesus wept.")
self.assertEqual(results[0]["valid"], False)
self.assertEqual(
results[0]["variables"],
{
Expand Down
46 changes: 46 additions & 0 deletions yvs/customize_refformat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
# coding=utf-8

import json
import os
import re

import yvs.core as core
import yvs.filter_prefs as filter_prefs


def main(variables):
ref = core.get_ref("111/jhn.11.35", core.get_default_user_prefs())
ref_format = json.loads(variables["value_id"])
print(
json.dumps(
{
"response": re.sub(
r"\s*¬\s*",
"\n",
filter_prefs.get_ref_format_value(ref_format, ref)["name"],
),
"footer": " · ".join(
(
"Press enter to confirm {}".format(variables["pref_name"]),
"⎋ Return to results",
)
),
"behaviour": {
"response": "replace",
"scroll": "auto",
},
}
)
)


if __name__ == "__main__":
main(
{
"pref_id": os.environ["pref_id"],
"pref_name": os.environ["pref_name"],
"value_id": os.environ["value_id"],
"value_name": os.environ["value_name"],
}
)
8 changes: 8 additions & 0 deletions yvs/customize_refformat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# The Alfred 5.5 Text View can only run an executable script as input; it cannot
# execute arbitrary script code, which we ultimately need to do so we can run
# the yvs.customize_refformat as a module; therefore, this intermediate shell
# script is necessary to run yvs.customize_refformat in the proper module
# context
/usr/bin/python3 -m yvs.customize_refformat "$@"
9 changes: 8 additions & 1 deletion yvs/filter_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,14 @@ def get_value_result(value, user_prefs, pref_def):
"title": value["name"],
}

if value["id"] == user_prefs[pref_def["id"]]:
if value["id"] == user_prefs[pref_def["id"]] and pref_def["id"] == "refformat":
# If this value is the current value, indicate such
result["subtitle"] = (
"This is already your preferred {}; press Enter to tweak".format(
pref_def.get("short_name")
)
)
elif value["id"] == user_prefs[pref_def["id"]]:
# If this value is the current value, indicate such
result["subtitle"] = "This is already your preferred {}".format(
pref_def.get("short_name")
Expand Down

0 comments on commit 04ac2d8

Please sign in to comment.