"""Functions that will be exposed in Jinja2.Add yours over the prompt2_jinja2 entry point plugin!Note that all prompt paths are added to the Jinja2 loader, so, you can alreadyinclude your prompts in your prompts:: {% include('your_prompt.txt') %}Or even go crazy with ``{% extend %}`` and ``{% macro %}``!"""importcli2importos
[docs]deffile(path):""" Show a file path content with context markers. It will render:: path/to/file source code: ``` <source code here> ``` :param path: File path """returnf'\n\n{path} source code:\n```\n{read(path)}\n```\n\n\n'
[docs]defread(path):""" Read a file from the filesystem :param path: Path of the file to read. """withopen(path,'r')asf:content=f.read()returncontent
[docs]defshell(*command,**env):""" Show a command output with context markers. It will render:: Output of `command line`: ``` <output here> ``` :param command: Command :param env: Environment variables """proc=cli2.Proc(*command,quiet=True,**env).wait()returnf'\n\nOutput of `{proc.cmd}`:\n```\n{proc.out}\n```\n\n\n'
[docs]defexec(*command,**env):""" Execute a command and return the full output. :param command: String or args list. """returncli2.Proc(*command,quiet=True,**env).wait().out
[docs]defdirs(path=None):""" Show the list of directories within a path. Renders:: Directories: - path/to/directory1 - path/to/directory2 :param path: Path to walk """path=pathoros.getcwd()return'\n'.join(['Directories:']+[str(_)for_incli2.Find(path).dirs()])
[docs]deffiles(path=None):""" Show the list of files within a path. Renders:: Files: - path/to/file1 - path/to/file2 :param path: Path to walk """path=pathoros.getcwd()return'\n'.join(['Files:']+[str(_)for_incli2.Find(path).files()])