Skip to content

Commit

Permalink
fix: improved tabcomplete to work well for paths with '~'
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Sep 29, 2024
1 parent 5a7c25a commit b4ff00e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions gptme/tabcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ def _process_completion(p: Path) -> str:
# Strip cwd from path
p = Path(str(p).replace(str(Path.cwd()) + "/", ""))

# Use ~/ if path is in home dir
p = Path(str(p).replace(str(Path.home()), "~/"))

# If path is a directory, add trailing slash
if p.exists() and p.is_dir():
if p.expanduser().exists() and p.expanduser().is_dir():
return str(p) + "/"
else:
return str(p)
Expand All @@ -69,9 +72,13 @@ def _matches(text: str) -> list[str]:
] + matching_files

# if text starts with ../, complete with parent dir
elif text.startswith(".."):
elif text.startswith("../"):
return [_process_completion(p) for p in Path("..").glob(text[3:] + "*")]

# if text starts with ~/, complete with home dir
elif text.startswith("~/"):
return [_process_completion(p) for p in Path.home().glob(text[2:] + "*")]

# else, complete with files in current dir
else:
return [_process_completion(p) for p in Path.cwd().glob(text + "*")]

0 comments on commit b4ff00e

Please sign in to comment.