Skip to content

Optional Template for New File - Feature Request #360

@NicholasLinderWood

Description

@NicholasLinderWood

hello hello! Thank you for creating babi as well as for all of your other educational material! I've been using babi and was wondering about a possible new feature which would (optionally) populate the editor with template text when creating a new file. After looking through the source code, here is one idea I've come up with for how this might be implemented.

  1. Add an optional command line argument indicating whether to use a template (and if so which. only applicable if no filename is given or if the given filename doesn't exist)
  2. Pass that argument along to the File.ensure_loaded method.
  3. In the case where the passed filename does not exist or filename is None, instead of passing the empty string to get_lines, call a function which returns a string to pass in based on that command line argument (and perhaps other info).
  4. Create babi/resources/templates.py which will:
    a. Store various text templates
    b. Contain the function referenced in 3.

If we think there would reasonably be only one template per file extension, then I'd lean toward making the command line argument a flag and then parse the filename to determine which flag to use. Then we could have something like babi t.py --template yielding

image

If not, then I think the command line argument would need to indicate which template to use.

I'd be very interested in hearing your thoughts. Thanks for your time and consideration!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions