-
Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy pathedit.py
More file actions
73 lines (59 loc) · 1.88 KB
/
edit.py
File metadata and controls
73 lines (59 loc) · 1.88 KB
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
"""CLI for ``tmuxp edit`` subcommand."""
from __future__ import annotations
import logging
import os
import subprocess
import typing as t
from tmuxp._internal.private_path import PrivatePath
from tmuxp.workspace.finders import find_workspace_file
from ._colors import Colors, build_description, get_color_mode
from .utils import tmuxp_echo
logger = logging.getLogger(__name__)
EDIT_DESCRIPTION = build_description(
"""
Open tmuxp workspace file in your system editor ($EDITOR).
""",
(
(
None,
[
"tmuxp edit myproject",
"tmuxp edit ./workspace.yaml",
],
),
),
)
if t.TYPE_CHECKING:
import argparse
import pathlib
from typing import TypeAlias
CLIColorModeLiteral: TypeAlias = t.Literal["auto", "always", "never"]
def create_edit_subparser(
parser: argparse.ArgumentParser,
) -> argparse.ArgumentParser:
"""Augment :class:`argparse.ArgumentParser` with ``edit`` subcommand."""
parser.add_argument(
dest="workspace_file",
metavar="workspace-file",
type=str,
help="checks current tmuxp and current directory for workspace files.",
)
return parser
def command_edit(
workspace_file: str | pathlib.Path,
parser: argparse.ArgumentParser | None = None,
color: CLIColorModeLiteral | None = None,
) -> None:
"""Entrypoint for ``tmuxp edit``, open tmuxp workspace file in system editor."""
color_mode = get_color_mode(color)
colors = Colors(color_mode)
workspace_file = find_workspace_file(workspace_file)
sys_editor = os.environ.get("EDITOR", "vim")
tmuxp_echo(
colors.muted("Opening ")
+ colors.info(str(PrivatePath(workspace_file)))
+ colors.muted(" in ")
+ colors.highlight(sys_editor, bold=False)
+ colors.muted("..."),
)
subprocess.call([sys_editor, workspace_file])