-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.py
More file actions
62 lines (51 loc) · 1.57 KB
/
Copy patheditor.py
File metadata and controls
62 lines (51 loc) · 1.57 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
"""Editor integration utilities for QuantCoder CLI."""
import subprocess
import shutil
import logging
from pathlib import Path
from typing import Optional
logger = logging.getLogger(__name__)
def open_in_editor(file_path: str, editor: str = "zed") -> bool:
"""
Open a file in the specified editor.
Args:
file_path: Path to the file to open
editor: Editor command (zed, code, vim, nvim, etc.)
Returns:
True if editor launched successfully, False otherwise
"""
path = Path(file_path)
if not path.exists():
logger.error(f"File not found: {file_path}")
return False
# Check if editor is available
editor_path = shutil.which(editor)
if not editor_path:
logger.error(f"Editor '{editor}' not found in PATH")
return False
try:
# Launch editor (non-blocking)
subprocess.Popen(
[editor, str(path)],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
start_new_session=True
)
logger.info(f"Opened {file_path} in {editor}")
return True
except Exception as e:
logger.error(f"Failed to open editor: {e}")
return False
def get_editor_display_name(editor: str) -> str:
"""Get a friendly display name for the editor."""
editor_names = {
"zed": "Zed",
"code": "VS Code",
"vim": "Vim",
"nvim": "Neovim",
"nano": "Nano",
"subl": "Sublime Text",
"atom": "Atom",
"emacs": "Emacs",
}
return editor_names.get(editor, editor)