Fast file completer class.
| 72 | |
| 73 | |
| 74 | class FastFilesCompleter: |
| 75 | class="st">""class="st">"Fast file completer class."class="st">"" |
| 76 | |
| 77 | def __init__(self, directories: bool = True) -> None: |
| 78 | self.directories = directories |
| 79 | |
| 80 | def __call__(self, prefix: str, **kwargs: Any) -> list[str]: |
| 81 | class="cm"># Only called on non option completions. |
| 82 | if os.sep in prefix[1:]: |
| 83 | prefix_dir = len(os.path.dirname(prefix) + os.sep) |
| 84 | else: |
| 85 | prefix_dir = 0 |
| 86 | completion = [] |
| 87 | globbed = [] |
| 88 | if class="st">"*" not in prefix and class="st">"?" not in prefix: |
| 89 | class="cm"># We are on unix, otherwise no bash. |
| 90 | if not prefix or prefix[-1] == os.sep: |
| 91 | globbed.extend(glob(prefix + class="st">".*")) |
| 92 | prefix += class="st">"*" |
| 93 | globbed.extend(glob(prefix)) |
| 94 | for x in sorted(globbed): |
| 95 | if os.path.isdir(x): |
| 96 | x += class="st">"/" |
| 97 | class="cm"># Append stripping the prefix (like bash, not like compgen). |
| 98 | completion.append(x[prefix_dir:]) |
| 99 | return completion |
| 100 | |
| 101 | |
| 102 | if os.environ.get(class="st">"_ARGCOMPLETE"): |
no outgoing calls