Skip to content

Feature request: path completion with pathlib objects #10427

Open

Description

@michaelaye

So, I love how ipython can path-complete strings to dig through your folders.
But I increasingly work with pathlib.Path objects for their increased readability and useful object attributes to access sub-paths.
Would it be possible to have ipython to be able to path-complete on a pathlib.Path folder?
So, I would like to be able to do something like this:

from pathlib import Path

root = Path("/abc/myfolder")

f1 = root / "f342<TAB>"
f2 = root / "f569<TAB>"

Hope this is understandable? With I mean I press the TAB key at that point, to have ipython complete that string part of the full path.

Cheers!

Activity

  1. modified the milestone: wishlist on Apr 10, 2017
  2. takluyver commented on Apr 11, 2017

    @takluyver
    Member

    I like the idea, but with our current tab completion machinery this would be pretty difficult, I think.

  3. carlsmith commented on Apr 11, 2017

    @carlsmith
    Contributor

    I wrapped the Path constructor in a line magic for doing a similar thing interactively.

    from pathlib import Path
    
    @line_magic
    def path(args): return Path(args)
    
    del path

    With that set up, you can then do stuff like this (with tab completion):

    home = %path ~/

    It's of pretty limited use, but it lets you create paths using tab completion when working interactively.

  4. takluyver commented on Apr 11, 2017

    @takluyver
    Member

    Neat :-)

  5. michaelaye commented on Apr 11, 2017

    @michaelaye
    ContributorAuthor

    Thanks! Where can I find the line_magic decorator?

  6. carlsmith commented on Apr 11, 2017

    @carlsmith
    Contributor

    Opps! Sorry.

    from IPython.core.magic import register_line_magic as line_magic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions