Skip to content

Commit

Permalink
feat: execute commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Apr 6, 2021
1 parent 3d52fc9 commit 0a5f47f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ To get the URI in a more convenient way you can use the `Copy Advanced URI` butt
| append | daily=true, data, mode=append | Only appends `data` to today's daily note. The file will be created, if the file does not already exist |
| prepend | daily=true, data, mode=prepend | Only prepends `data` to today's daily note. The file will be created, if the file does not already exist |

## Execute command

| / | parameters | explanation |
| --------------- | ----------- | ---------------------------- |
| execute by name | commandname | Executes command by its name |
| execute by id | commandid | Executes command by its id |

# Examples

**Write** "Hello World" to "my-file.md":
Expand Down
20 changes: 20 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ interface Parameters {
mode: "overwrite" | "append" | "prepend";
heading: string;
block: string;
commandname: string,
commandid: string,
}

export default class AdvancedURI extends Plugin {
Expand All @@ -31,6 +33,9 @@ export default class AdvancedURI extends Plugin {
if (parameters.workspace) {
this.handleWorkspace(parameters.workspace);

} else if (parameters.commandname || parameters.commandid) {
this.handleCommand(parameters);

} else if (parameters.filepath && parameters.data) {
this.handleWrite(parameters);

Expand Down Expand Up @@ -98,6 +103,21 @@ export default class AdvancedURI extends Plugin {
}
}

handleCommand(parameters: Parameters) {
if (parameters.commandid) {
(this.app as any).commands.executeCommandById(parameters.commandid);
} else if (parameters.commandname) {
const rawCommands = (this.app as any).commands.commands;
for (const command in rawCommands) {
if (rawCommands[command].name === parameters.commandname) {
rawCommands[command].callback();
return;
}

}
}
}

async handleWrite(parameters: Parameters) {
let path = normalizePath(parameters.filepath);
if (!path.endsWith(".md")) {
Expand Down

0 comments on commit 0a5f47f

Please sign in to comment.