-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange_directory.py
47 lines (36 loc) · 1.44 KB
/
change_directory.py
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
"""Provides a command for changing the directory of the local file viewer."""
##############################################################################
# Python imports.
from pathlib import Path
##############################################################################
# Textual imports.
from textual.widget import Widget
##############################################################################
# Local imports.
from ...messages import SetLocalViewRoot
from .base_command import InputCommand
##############################################################################
class ChangeDirectoryCommand(InputCommand):
"""Change the root directory of the local file browser"""
COMMAND = "`chdir`"
ALIASES = "`cd`, `dir`, `ls`"
ARGUMENTS = "`<directory>`"
@classmethod
def handle(cls, text: str, for_widget: Widget) -> bool:
"""Handle the command.
Args:
text: The text of the command.
for_widget: The widget to handle the command for.
Returns:
`True` if the command was handled; `False` if not.
"""
command, directory = cls.split_command(text)
if (
cls.is_command(command)
and directory
and (root := Path(directory).expanduser()).is_dir()
):
for_widget.post_message(SetLocalViewRoot(Path(root).resolve()))
return True
return False
### change_directory.py ends here