You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted an option to run just --choose with executing the choosen recipe but instead output it to the prompt so that it can be edited before excution. This is great for recipes that take arguments and also gives a more valuable shell history. Failing to do that in rust that I don't know a lot about, it hacked together something with python + zsh
First here's a python script to extract all recipe paths (recursing into submodules)
#!/usr/bin/env python3
import json
import subprocess
from json.decoder import JSONDecodeError
def get_just_json():
try:
return json.loads(
subprocess.run(
["just", "--dump", "--dump-format", "json"],
capture_output=True,
text=True,
).stdout
)
except JSONDecodeError:
pass
def walk_data(data):
results = []
def _walk_data(data, module_path):
try:
recipes = data["recipes"]
for recipe in [r for r in recipes if not r.startswith("_")]:
doc = recipes[recipe]["doc"]
namepath = recipes[recipe]["namepath"].replace("::", " ")
results.append((namepath, doc))
except AttributeError as err:
pass
try:
for module in data["modules"].keys():
new_data = data["modules"][module]
new_module_path = [*module_path, module]
_walk_data(new_data, new_module_path)
except AttributeError as err:
pass
_walk_data(data, [])
return results
if data := get_just_json():
lines = walk_data(data)
n_chars = max([len(l[0]) for l in lines])
for path, doc in walk_data(data):
print(f"{path:<{n_chars}} -- {doc}")
Then I put together this zsh function to invoke it, pass the output to fzf and output the chosen recipe to the prompt for editing.
Halfway through the process I realized that maybe just wouldn't be able to ouput the the chosen recipe to the prompt for editing ( i.e. to do what "print -z" does in zsh) so just won't be able to do the entire thing that these to scripts do together. But it would be nice if just could list available recipe paths (i.e. the thing the python script does).
The text was updated successfully, but these errors were encountered:
Here's a version of the zsh function that does the whole thing without the need for any python script. The python version had the nice bonus that it would output the doc string next to the recipe path, but this is a lot simpler.
I wanted an option to run just --choose with executing the choosen recipe but instead output it to the prompt so that it can be edited before excution. This is great for recipes that take arguments and also gives a more valuable shell history. Failing to do that in rust that I don't know a lot about, it hacked together something with python + zsh
First here's a python script to extract all recipe paths (recursing into submodules)
Then I put together this zsh function to invoke it, pass the output to
fzf
and output the chosen recipe to the prompt for editing.Halfway through the process I realized that maybe
just
wouldn't be able to ouput the the chosen recipe to the prompt for editing ( i.e. to do what "print -z" does in zsh) sojust
won't be able to do the entire thing that these to scripts do together. But it would be nice ifjust
could list available recipe paths (i.e. the thing the python script does).The text was updated successfully, but these errors were encountered: