Skip to content

Commit cbeca1d

Browse files
Find VSCode settings in $XDG_CONFIG_HOME (#1074)
Co-authored-by: Andreas Arvidsson <[email protected]>
1 parent 32e66b1 commit cbeca1d

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/apps/vscode_settings.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,49 +58,50 @@ def vscode_get_setting_with_fallback(
5858
"""
5959
try:
6060
return actions.user.vscode_get_setting(key, default_value), False
61-
except Exception as e:
61+
except Exception:
6262
print(fallback_message)
6363
traceback.print_exc()
6464
return fallback_value, True
6565

6666

67-
def pick_path(paths: list[Path]):
67+
def pick_path(paths: list[Path]) -> Path:
6868
existing_paths = [path for path in paths if path.exists()]
6969
return max(existing_paths, key=lambda path: path.stat().st_mtime)
7070

7171

7272
@mac_ctx.action_class("user")
7373
class MacUserActions:
7474
def vscode_settings_path() -> Path:
75+
application_support = Path.home() / "Library/Application Support"
7576
return pick_path(
7677
[
77-
Path(
78-
f"{os.environ['HOME']}/Library/Application Support/Code/User/settings.json"
79-
),
80-
Path(
81-
f"{os.environ['HOME']}/Library/Application Support/VSCodium/User/settings.json"
82-
),
78+
application_support / "Code/User/settings.json",
79+
application_support / "VSCodium/User/settings.json",
8380
]
8481
)
8582

8683

8784
@linux_ctx.action_class("user")
8885
class LinuxUserActions:
8986
def vscode_settings_path() -> Path:
87+
xdg_config_home = Path(
88+
os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")
89+
)
9090
return pick_path(
9191
[
92-
Path(f"{os.environ['HOME']}/.config/Code/User/settings.json"),
93-
Path(f"{os.environ['HOME']}/.config/VSCodium/User/settings.json"),
92+
xdg_config_home / "Code/User/settings.json",
93+
xdg_config_home / "VSCodium/User/settings.json",
9494
]
9595
)
9696

9797

9898
@windows_ctx.action_class("user")
9999
class WindowsUserActions:
100100
def vscode_settings_path() -> Path:
101+
appdata = Path(os.environ["APPDATA"])
101102
return pick_path(
102103
[
103-
Path(f"{os.environ['APPDATA']}/Code/User/settings.json"),
104-
Path(f"{os.environ['APPDATA']}/VSCodium/User/settings.json"),
104+
appdata / "Code/User/settings.json",
105+
appdata / "VSCodium/User/settings.json",
105106
]
106107
)

0 commit comments

Comments
 (0)