Skip to content

Commit caa7143

Browse files
authored
Merge pull request #14 from yuhldr/main
refactor: #8
2 parents 2a40bfa + 0c8c311 commit caa7143

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

vscode_nautilus_workspaces.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from gi.repository import Nautilus, GObject, GLib
2-
import os
1+
import json
32
import logging
4-
from urllib.parse import unquote
3+
import os
54
from subprocess import call
6-
import json
5+
from urllib.parse import unquote
6+
7+
from gi.repository import GLib, GObject, Nautilus
78

89
# Configure logging
910
logging.basicConfig(
@@ -92,25 +93,28 @@ def _open_workspace(self, menu, workspace_path):
9293
self.launch_vscode(menu, [workspace_path])
9394

9495
def _get_name(self, workspace):
96+
# Handle file:// paths
9597
if workspace.startswith("file://"):
96-
return workspace.replace("file://", "").replace(GLib.get_home_dir(), "~")
97-
98-
if workspace.startswith("vscode-remote://"):
99-
workspace_name = workspace.replace("vscode-remote://", "")
100-
if workspace_name.startswith("ssh-remote+"):
101-
workspace_name = workspace_name.replace("ssh-remote+", "")
102-
if "/" not in workspace_name:
103-
return None
104-
wns = workspace_name.split("/")
105-
if len(wns) < 2:
106-
return None
107-
ssh_host = wns[0]
108-
workspace_name = workspace_name.replace(ssh_host, "")
109-
if len(wns) >= 4:
110-
workspace_name = "~/" + "/".join(wns[3:])
111-
return f"[SHH: {ssh_host}] {workspace_name}"
112-
113-
return workspace
98+
path = workspace.replace("file://", "")
99+
return path.replace(GLib.get_home_dir(), "~")
100+
101+
# Early return for non-vscode-remote paths
102+
if not workspace.startswith("vscode-remote://ssh-remote+"):
103+
return workspace
104+
105+
# Process SSH remote workspace path
106+
parts = workspace[len("vscode-remote://ssh-remote+"):].split("/", 3)
107+
108+
# Validate path structure
109+
if len(parts) < 2:
110+
return None
111+
ssh_host = parts[0]
112+
113+
# Construct workspace path
114+
workspace_path = f"~/{parts[3]}" if len(
115+
parts) >= 4 else "/".join(parts[1:])
116+
117+
return f"[SSH: {ssh_host}] {workspace_path}"
114118

115119
def get_background_items(self, window):
116120
recent_workspaces = self._get_recent_workspaces()

0 commit comments

Comments
 (0)