File: filepath.md

package info (click to toggle)
python-inquirerpy 0.3.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,088 kB
  • sloc: python: 9,463; makefile: 15
file content (78 lines) | stat: -rw-r--r-- 1,783 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# filepath

A text prompt which provides auto completion for system paths.

## Example

![demo](https://assets.kazhala.me/InquirerPy/filepath.gif)

<details>
  <summary>Classic Syntax (PyInquirer)</summary>

```{eval-rst}
.. literalinclude :: ../../../examples/classic/filepath.py
   :language: python
```

</details>

<details open>
  <summary>Alternate Syntax</summary>

```{eval-rst}
.. literalinclude :: ../../../examples/alternate/filepath.py
   :language: python
```

</details>

## Keybindings

```{seealso}
{ref}`pages/kb:Keybindings`
```

```{include} ../kb.md
:start-after: <!-- start kb -->
:end-before: <!-- end kb -->
```

In addition the default keybindings, you can use `ctrl-space` to trigger completion window popup.

```
{
    "completion": [{"key": "c-space"}]  # force completion popup
}
```

## Symbols and ENV Variables

The auto completion can handle `~` and will start triggering completion for the home directory. However it does not handle ENV variable
such as `$HOME`.

If you wish to support ENV variables completion, look into `prompt_toolkit` [documentation](https://python-prompt-toolkit.readthedocs.io/en/master/pages/asking_for_input.html#autocompletion)
and create a custom completion class. Directly use the {ref}`pages/prompts/input:InputPrompt` with the parameter `completer`.

```{seealso}
{class}`InquirerPy.prompts.filepath.FilePathCompleter`
```

## Excluding File Types

This class contains 2 basic variables `only_directories` and `only_files` that can control whether to only list
files or directories in the completion.

```{note}
`only_directories` takes higher priority over `only_files`.
```

```{seealso}
[Example](#example)
```

## Reference

```{eval-rst}
.. autoclass:: InquirerPy.prompts.filepath.FilePathPrompt
    :noindex:
```