Created
October 5, 2022 00:39
-
-
Save joeddav/878a2dc9731b22fd47adb1cc3cbfe603 to your computer and use it in GitHub Desktop.
Safe file deletion in Obsidian with QuickAdd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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