diff --git a/README.md b/README.md index 2faa757..67d78ea 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ - # dotfiles Configure dotfiles from your VS Code settings so they're always available. + +## Extension Settings + +* `dotfiles.directory`: Base directory path for all config files to be written. +* `dotfiles.files`: Files to be written to the configured directory, where key is the relative path to the file and value is the content of the file. diff --git a/package.json b/package.json index 056e616..719cd13 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "displayName": "dotfiles", "publisher": "grg", "description": "Apply dotfiles from settings", - "version": "0.0.1", + "version": "0.1.0", + "preview": true, "engines": { "vscode": "^1.74.0" }, @@ -29,17 +30,10 @@ "markdownDescription": "Path to config directory. If unset, uses `$XDG_CONFIG_DIR` with fallback to `$HOME/.config`.", "order": 1 }, - "dotfiles.file": { - "type": "string", - "default": "fish/conf.d/vscode.fish", - "markdownDescription": "Path to config file relative to `#dotfiles.directory#` directory.", + "dotfiles.files": { + "type": "object", + "markdownDescription": "Files to apply where key is file path relative to `#dotfiles.directory#` and value is file content.", "order": 2 - }, - "dotfiles.content": { - "type": "string", - "description": "Content of config file.", - "editPresentation": "multilineText", - "order": 3 } } } @@ -53,7 +47,7 @@ "test": "vscode-test" }, "devDependencies": { - "@types/vscode": "^1.87.0", + "@types/vscode": "^1.74.0", "@types/mocha": "^10.0.6", "@types/node": "18.x", "@typescript-eslint/eslint-plugin": "^7.0.2", diff --git a/src/extension.ts b/src/extension.ts index 5d6bfde..3f3d33b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,20 +6,21 @@ const configNamespace = "dotfiles"; async function apply() { const config = vscode.workspace.getConfiguration(configNamespace); - const directory = config.get("directory") || process.env["XDG_CONFIG_DIR"] || path.join(process.env["HOME"]!, ".config"); - const filePath = path.join(directory, config.get("file") || "fish/conf.d/vscode.fish"); - fs.stat(filePath, (err, _) => { - if (err) { - vscode.window.showWarningMessage(`${filePath} does not exist`); - return; - } - const data = config.get("content"); - if (!data) { - vscode.window.showInformationMessage("No content to write"); - return; - } - fs.writeFile(filePath, data, { encoding: "utf-8", mode: "w" }, () => { }); - }); + const directory = config.get("directory", process.env["XDG_CONFIG_DIR"] ?? path.join(process.env["HOME"]!, ".config")); + const files = Object.entries(config.get("files", {})); + for (const [file, content] of files) { + const filePath = path.join(directory, file); + fs.stat(filePath, (err, _) => { + if (err) { + vscode.window.showWarningMessage(`${filePath} does not exist`); + return; + } + if (!content) { + return; + } + fs.writeFile(filePath, content, { encoding: "utf-8", mode: "w" }, () => { }); + }); + } } export function activate(context: vscode.ExtensionContext) {