From dd8a930e68c5b4eba6e2e1ece162b3efdbaa77f8 Mon Sep 17 00:00:00 2001 From: hyperoot Date: Thu, 8 Aug 2024 06:51:27 +0000 Subject: [PATCH] added support for linux and macos --- src/extension.ts | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 22d3c74..132f450 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,18 +1,40 @@ import * as vscode from "vscode"; import * as fs from "fs"; import * as path from "path"; +import * as os from "os"; export function activate(context: vscode.ExtensionContext) { let settings_organizer_global = vscode.commands.registerCommand( "extension.settings-organizer-global", () => { - const appData = process.env.APPDATA || process.env.HOME || ""; - const userSettingsPath = path.join( - appData, - "Code", - "User", - "settings.json" - ); + const platform = os.platform(); + let userSettingsPath = ""; + + if (platform === "win32") { + userSettingsPath = path.join( + process.env.APPDATA || "", + "Code", + "User", + "settings.json" + ); + } else if (platform === "darwin") { + userSettingsPath = path.join( + process.env.HOME || "", + "Library", + "Application Support", + "Code", + "User", + "settings.json" + ); + } else if (platform === "linux") { + userSettingsPath = path.join( + process.env.HOME || "", + ".config", + "Code", + "User", + "settings.json" + ); + } // Log the path for debugging console.log(`Looking for settings.json at: ${userSettingsPath}`);