Skip to content

Instantly share code, notes, and snippets.

@joeddav
Created October 5, 2022 00:39
Show Gist options
  • Save joeddav/878a2dc9731b22fd47adb1cc3cbfe603 to your computer and use it in GitHub Desktop.
Save joeddav/878a2dc9731b22fd47adb1cc3cbfe603 to your computer and use it in GitHub Desktop.
Safe file deletion in Obsidian with QuickAdd
module.exports = async function safeDelete(params) {
const {app, quickAddApi: {inputPrompt}} = params;
const file = app.workspace.getActiveFile();
let shouldDelete = false;
if (file.stat.size === 0) {
shouldDelete = true;
} else {
const input = await inputPrompt(
'Type "delete" to confirm non-empty file deletion:'
)
shouldDelete = (input === "delete");
}
if (shouldDelete) {
await app.vault.trash(file, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment