├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.md │ ├── feature_request.md │ └── other.md └── workflows │ └── nodejs-ci.yml ├── .gitignore ├── LICENSE ├── README.md ├── esbuild.config.mjs ├── jest.config.ts ├── manifest.json ├── package-lock.json ├── package.json ├── src ├── add-alias-modal.ts ├── example.test.ts ├── main.ts ├── setting-tab.ts └── uncover-obsidian.ts ├── styles.css ├── tsconfig.json └── versions.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 4 10 | tab_width = 4 11 | 12 | [*.json] 13 | indent_size = 2 14 | tab_width = 2 15 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | 3 | main.js 4 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "plugins": [ 5 | "@typescript-eslint" 6 | ], 7 | "extends": [ 8 | "eslint:recommended", 9 | "plugin:@typescript-eslint/eslint-recommended", 10 | "plugin:@typescript-eslint/recommended" 11 | ], 12 | "parserOptions": { 13 | "sourceType": "module" 14 | }, 15 | "rules": { 16 | "no-unused-vars": "off", 17 | "@typescript-eslint/no-unused-vars": [ 18 | "error", 19 | { 20 | "args": "none" 21 | } 22 | ], 23 | "@typescript-eslint/ban-ts-comment": "off", 24 | "no-prototype-builtins": "off", 25 | "@typescript-eslint/no-empty-function": "off" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Describe the bug 11 | 12 | 13 | ### To Reproduce 14 | 21 | 22 | ### Expected behavior 23 | 24 | 25 | ### Screenshots 26 | 27 | 28 | ### Enviroment 29 | 30 | - Plugin Version: 31 | - Obsidian Version: 32 | - Platform OS: 33 | - Platform OS Version: 34 | 35 | ### Additional context 36 | 37 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Is your feature request related to a problem? Please describe. 11 | 12 | 13 | ### Describe the solution you'd like 14 | 15 | 16 | ### Describe alternatives you've considered 17 | 18 | 19 | ### Additional context 20 | 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/other.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: other 3 | about: free-format 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/workflows/nodejs-ci.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | matrix: 19 | node-version: [18.x, 20.x] 20 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ 21 | 22 | steps: 23 | - uses: actions/checkout@v3 24 | - name: Use Node.js ${{ matrix.node-version }} 25 | uses: actions/setup-node@v3 26 | with: 27 | node-version: ${{ matrix.node-version }} 28 | cache: 'npm' 29 | - run: npm ci 30 | - run: npm run build --if-present 31 | - run: npm test 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # vscode 2 | .vscode 3 | 4 | # Intellij 5 | *.iml 6 | .idea 7 | 8 | # npm 9 | node_modules 10 | 11 | # Don't include the compiled main.js file in the repo. 12 | # They should be uploaded to GitHub releases instead. 13 | main.js 14 | 15 | # Exclude sourcemaps 16 | *.map 17 | 18 | # obsidian 19 | data.json 20 | 21 | # jest 22 | coverage 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 yajamon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Obsidian Command Alias Plugin 2 | 3 | This plugin is provide alias for other command. 4 | The translated words help you understand the intent of the command, but they are tedious to type. 5 | 6 | ## Usage 7 | 8 | [How to add Alias](https://user-images.githubusercontent.com/6084855/167056118-0b4120d1-fd97-4c82-bad1-83981409147d.mp4) 9 | 10 | - Run command `Command Alias: Add command alias`. 11 | - Choose command. 12 | - Naming alias. 13 | - Open the command palette and enter an alias in the box to narrow down the command. 14 | 15 | ### Remove alias 16 | 17 | - Open SettingTab. 18 | - Remove alias. 19 | 20 | ## How to start develop 21 | 22 | 1. `npm install` 23 | 2. `npm run dev` 24 | -------------------------------------------------------------------------------- /esbuild.config.mjs: -------------------------------------------------------------------------------- 1 | import esbuild from "esbuild"; 2 | import process from "process"; 3 | import builtins from "builtin-modules"; 4 | 5 | const banner = 6 | `/* 7 | THIS IS A GENERATED/BUNDLED FILE BY ESBUILD 8 | if you want to view the source visit the plugins github repository 9 | */ 10 | `; 11 | 12 | const prod = (process.argv[2] === 'production'); 13 | 14 | const context = await esbuild.context({ 15 | banner: { 16 | js: banner, 17 | }, 18 | entryPoints: ['src/main.ts'], 19 | bundle: true, 20 | external: [ 21 | "obsidian", 22 | "electron", 23 | "@codemirror/autocomplete", 24 | "@codemirror/collab", 25 | "@codemirror/commands", 26 | "@codemirror/language", 27 | "@codemirror/lint", 28 | "@codemirror/search", 29 | "@codemirror/state", 30 | "@codemirror/view", 31 | "@lezer/common", 32 | "@lezer/highlight", 33 | "@lezer/lr", 34 | ...builtins], 35 | format: 'cjs', 36 | target: "es2018", 37 | logLevel: "info", 38 | sourcemap: prod ? false : 'inline', 39 | treeShaking: true, 40 | outfile: 'main.js', 41 | }); 42 | 43 | if (prod) { 44 | await context.rebuild(); 45 | process.exit(0); 46 | } else { 47 | await context.watch(); 48 | } 49 | -------------------------------------------------------------------------------- /jest.config.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * For a detailed explanation regarding each configuration property and type check, visit: 3 | * https://jestjs.io/docs/configuration 4 | */ 5 | 6 | export default { 7 | // All imported modules in your tests should be mocked automatically 8 | // automock: false, 9 | 10 | // Stop running tests after `n` failures 11 | // bail: 0, 12 | 13 | // The directory where Jest should store its cached dependency information 14 | // cacheDirectory: "/tmp/jest_rs", 15 | 16 | // Automatically clear mock calls, instances and results before every test 17 | // clearMocks: false, 18 | 19 | // Indicates whether the coverage information should be collected while executing the test 20 | collectCoverage: true, 21 | 22 | // An array of glob patterns indicating a set of files for which coverage information should be collected 23 | // collectCoverageFrom: undefined, 24 | 25 | // The directory where Jest should output its coverage files 26 | coverageDirectory: "coverage", 27 | 28 | // An array of regexp pattern strings used to skip coverage collection 29 | // coveragePathIgnorePatterns: [ 30 | // "/node_modules/" 31 | // ], 32 | 33 | // Indicates which provider should be used to instrument code for coverage 34 | coverageProvider: "v8", 35 | 36 | // A list of reporter names that Jest uses when writing coverage reports 37 | // coverageReporters: [ 38 | // "json", 39 | // "text", 40 | // "lcov", 41 | // "clover" 42 | // ], 43 | 44 | // An object that configures minimum threshold enforcement for coverage results 45 | // coverageThreshold: undefined, 46 | 47 | // A path to a custom dependency extractor 48 | // dependencyExtractor: undefined, 49 | 50 | // Make calling deprecated APIs throw helpful error messages 51 | // errorOnDeprecated: false, 52 | 53 | // Force coverage collection from ignored files using an array of glob patterns 54 | // forceCoverageMatch: [], 55 | 56 | // A path to a module which exports an async function that is triggered once before all test suites 57 | // globalSetup: undefined, 58 | 59 | // A path to a module which exports an async function that is triggered once after all test suites 60 | // globalTeardown: undefined, 61 | 62 | // A set of global variables that need to be available in all test environments 63 | // globals: {}, 64 | 65 | // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers. 66 | // maxWorkers: "50%", 67 | 68 | // An array of directory names to be searched recursively up from the requiring module's location 69 | // moduleDirectories: [ 70 | // "node_modules" 71 | // ], 72 | 73 | // An array of file extensions your modules use 74 | // moduleFileExtensions: [ 75 | // "js", 76 | // "jsx", 77 | // "ts", 78 | // "tsx", 79 | // "json", 80 | // "node" 81 | // ], 82 | 83 | // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module 84 | // moduleNameMapper: {}, 85 | 86 | // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader 87 | // modulePathIgnorePatterns: [], 88 | 89 | // Activates notifications for test results 90 | // notify: false, 91 | 92 | // An enum that specifies notification mode. Requires { notify: true } 93 | // notifyMode: "failure-change", 94 | 95 | // A preset that is used as a base for Jest's configuration 96 | preset: "ts-jest", 97 | 98 | // Run tests from one or more projects 99 | // projects: undefined, 100 | 101 | // Use this configuration option to add custom reporters to Jest 102 | // reporters: undefined, 103 | 104 | // Automatically reset mock state before every test 105 | // resetMocks: false, 106 | 107 | // Reset the module registry before running each individual test 108 | // resetModules: false, 109 | 110 | // A path to a custom resolver 111 | // resolver: undefined, 112 | 113 | // Automatically restore mock state and implementation before every test 114 | // restoreMocks: false, 115 | 116 | // The root directory that Jest should scan for tests and modules within 117 | // rootDir: undefined, 118 | 119 | // A list of paths to directories that Jest should use to search for files in 120 | // roots: [ 121 | // "" 122 | // ], 123 | 124 | // Allows you to use a custom runner instead of Jest's default test runner 125 | // runner: "jest-runner", 126 | 127 | // The paths to modules that run some code to configure or set up the testing environment before each test 128 | // setupFiles: [], 129 | 130 | // A list of paths to modules that run some code to configure or set up the testing framework before each test 131 | // setupFilesAfterEnv: [], 132 | 133 | // The number of seconds after which a test is considered as slow and reported as such in the results. 134 | // slowTestThreshold: 5, 135 | 136 | // A list of paths to snapshot serializer modules Jest should use for snapshot testing 137 | // snapshotSerializers: [], 138 | 139 | // The test environment that will be used for testing 140 | testEnvironment: "jsdom", 141 | 142 | // Options that will be passed to the testEnvironment 143 | // testEnvironmentOptions: {}, 144 | 145 | // Adds a location field to test results 146 | // testLocationInResults: false, 147 | 148 | // The glob patterns Jest uses to detect test files 149 | // testMatch: [ 150 | // "**/__tests__/**/*.[jt]s?(x)", 151 | // "**/?(*.)+(spec|test).[tj]s?(x)" 152 | // ], 153 | 154 | // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped 155 | // testPathIgnorePatterns: [ 156 | // "/node_modules/" 157 | // ], 158 | 159 | // The regexp pattern or array of patterns that Jest uses to detect test files 160 | // testRegex: [], 161 | 162 | // This option allows the use of a custom results processor 163 | // testResultsProcessor: undefined, 164 | 165 | // This option allows use of a custom test runner 166 | // testRunner: "jest-circus/runner", 167 | 168 | // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href 169 | // testURL: "http://localhost", 170 | 171 | // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout" 172 | // timers: "real", 173 | 174 | // A map from regular expressions to paths to transformers 175 | // transform: undefined, 176 | 177 | // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation 178 | // transformIgnorePatterns: [ 179 | // "/node_modules/", 180 | // "\\.pnp\\.[^\\/]+$" 181 | // ], 182 | 183 | // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them 184 | // unmockedModulePathPatterns: undefined, 185 | 186 | // Indicates whether each individual test should be reported during the run 187 | // verbose: undefined, 188 | 189 | // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode 190 | // watchPathIgnorePatterns: [], 191 | 192 | // Whether to use watchman for file crawling 193 | // watchman: true, 194 | }; 195 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "obsidian-command-alias-plugin", 3 | "name": "Command Alias", 4 | "version": "2.1.1", 5 | "minAppVersion": "0.15.0", 6 | "description": "This plugin gives aliases to Obsidian commands.", 7 | "author": "yajamon", 8 | "authorUrl": "https://github.com/yajamon/obsidian-command-alias-plugin", 9 | "isDesktopOnly": false 10 | } 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "obsidian-command-alias-plugin", 3 | "version": "0.12.0", 4 | "description": "This plugin is provide alias for other command. The translated words help you understand the intent of the command, but they are tedious to type.", 5 | "main": "main.js", 6 | "scripts": { 7 | "dev": "node esbuild.config.mjs", 8 | "build": "tsc --noEmit --skipLibCheck && node esbuild.config.mjs production", 9 | "test": "jest" 10 | }, 11 | "keywords": [], 12 | "author": "", 13 | "license": "MIT", 14 | "private": true, 15 | "devDependencies": { 16 | "@types/jest": "^27.5.0", 17 | "@types/node": "^17.0.31", 18 | "@typescript-eslint/eslint-plugin": "^5.29.0", 19 | "@typescript-eslint/parser": "^5.29.0", 20 | "builtin-modules": "^3.3.0", 21 | "esbuild": "^0.17.3", 22 | "eslint": "^8.6.0", 23 | "jest": "^27.5.0", 24 | "obsidian": "latest", 25 | "ts-jest": "^27.1.4", 26 | "ts-node": "^10.7.0", 27 | "tslib": "^2.4.0", 28 | "typescript": "^4.7.4" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/add-alias-modal.ts: -------------------------------------------------------------------------------- 1 | import { App, FuzzySuggestModal, Modal, Notice, Setting } from "obsidian"; 2 | import CommandAliasPlugin from "./main"; 3 | import { AppExtension } from "./uncover-obsidian"; 4 | 5 | interface CommandInfo { 6 | id: string; 7 | name: string; 8 | } 9 | 10 | export class CommandSuggestionModal extends FuzzySuggestModal { 11 | private plugin: CommandAliasPlugin; 12 | private items: CommandInfo[]; 13 | constructor(app: App, plugin: CommandAliasPlugin) { 14 | super(app); 15 | this.plugin = plugin; 16 | 17 | const appex = app as AppExtension; 18 | const items: CommandInfo[] = []; 19 | for (const id in appex.commands.commands) { 20 | // Don't loop aliases. 21 | if (id.startsWith('obsidian-command-alias-plugin:alias:')) { 22 | continue; 23 | } 24 | items.push({ 25 | id: id, 26 | name: appex.commands.commands[id].name, 27 | }) 28 | } 29 | this.items = items; 30 | } 31 | 32 | getItems(): CommandInfo[] { 33 | return this.items; 34 | } 35 | getItemText(item: CommandInfo): string { 36 | return item.name; 37 | } 38 | onChooseItem(item: CommandInfo, evt: MouseEvent | KeyboardEvent): void { 39 | const m = new NamingModal({ 40 | app: this.app, 41 | plugin: this.plugin, 42 | command: item, 43 | }); 44 | m.open(); 45 | } 46 | } 47 | 48 | type NamingModalParams = { 49 | app: App, 50 | plugin: CommandAliasPlugin, 51 | command: CommandInfo, 52 | } 53 | class NamingModal extends Modal { 54 | private plugin: CommandAliasPlugin; 55 | private command: CommandInfo; 56 | constructor(params: NamingModalParams) { 57 | const { app, plugin, command } = params; 58 | super(app); 59 | this.plugin = plugin; 60 | this.command = command; 61 | } 62 | 63 | onOpen() { 64 | const { contentEl } = this; 65 | contentEl.createEl('h2', { text: `Add alias: ${this.command.name}` }); 66 | 67 | let aliasName = "" 68 | new Setting(contentEl) 69 | .setName('Naming alias') 70 | .addText(text => text 71 | .setPlaceholder('add alias') 72 | .onChange(value => { 73 | aliasName = value.trim(); 74 | })) 75 | .addButton(button => button 76 | .setButtonText('Add') 77 | .onClick(async e => { 78 | if (aliasName === "") { 79 | new Notice('alias name is empty'); 80 | return; 81 | } 82 | this.plugin.addAliasSetting(aliasName, this.command.id); 83 | await this.plugin.saveSettings(); 84 | this.close(); 85 | this.plugin.unload(); 86 | this.plugin.load(); 87 | })); 88 | contentEl.find('input').focus(); 89 | } 90 | 91 | onClose() { 92 | const { contentEl } = this; 93 | contentEl.empty(); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/example.test.ts: -------------------------------------------------------------------------------- 1 | describe("Example", () => { 2 | test("1 less than 2", () => { 3 | const one: number = parseInt("1"); 4 | expect(one).toBeLessThan(2); 5 | }); 6 | }); 7 | 8 | export { }; 9 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { Command, Notice, Plugin } from 'obsidian'; 2 | import { AppExtension } from "./uncover-obsidian"; 3 | import { CommandAliasPluginSettingTab } from "./setting-tab"; 4 | import { CommandSuggestionModal } from "./add-alias-modal"; 5 | interface CommandAliasPluginSettings { 6 | aliases: AliasMap; 7 | commandDetection: { 8 | maxTry: number; 9 | msecOfInterval: number; 10 | } 11 | } 12 | 13 | type AliasMap = { 14 | [key: string]: Alias; 15 | } 16 | interface Alias { 17 | name: string; 18 | commandId: string; 19 | } 20 | 21 | const DEFAULT_SETTINGS: CommandAliasPluginSettings = { 22 | aliases: {}, 23 | commandDetection: { 24 | maxTry: 5, 25 | msecOfInterval: 200 26 | } 27 | } 28 | 29 | async function timeoutPromise(msec: number) { 30 | return new Promise((resolve) => { 31 | setTimeout(() => { 32 | resolve(null); 33 | }, msec); 34 | }); 35 | } 36 | 37 | export default class CommandAliasPlugin extends Plugin { 38 | settings: CommandAliasPluginSettings; 39 | 40 | async onload() { 41 | // const app = this.app as AppExtension; 42 | 43 | await this.loadSettings(); 44 | 45 | this.addCommand({ 46 | id: "add-alias", 47 | name: "Add command alias", 48 | callback: () => { 49 | const modal = new CommandSuggestionModal(this.app, this); 50 | modal.open(); 51 | }, 52 | }); 53 | 54 | this.addSettingTab(new CommandAliasPluginSettingTab(this.app, this)); 55 | 56 | const promises: Array> = []; 57 | for (const aliasId in this.settings.aliases) { 58 | if (!Object.prototype.hasOwnProperty.call(this.settings.aliases, aliasId)) { 59 | continue; 60 | } 61 | const p = this.addAliasCommand(aliasId); 62 | promises.push(p); 63 | } 64 | await Promise.all(promises); 65 | } 66 | 67 | private async addAliasCommand(aliasId: string) { 68 | const app = this.app as AppExtension; 69 | const { maxTry, msecOfInterval } = this.settings.commandDetection; 70 | 71 | const alias = this.settings.aliases[aliasId]; 72 | const detection = async () => { 73 | for (let tried = 0; tried < maxTry; tried += 1) { 74 | const ref = app.commands.commands[alias.commandId]; 75 | if (ref != null) { 76 | return Promise.resolve(ref); 77 | } 78 | await timeoutPromise(msecOfInterval) 79 | } 80 | return Promise.reject("Missing command"); 81 | }; 82 | const commandDetection = detection().then((target: Command) => { 83 | const command: Command = { 84 | id: `alias:${aliasId}`, 85 | name: `${alias.name}: ${target.name}`, 86 | }; 87 | if (target.callback) { 88 | command.callback = () => { 89 | const target = app.commands.commands[alias.commandId]; 90 | if (!target) { 91 | new Notice("Missing command. The command may be invalid."); 92 | return; 93 | } 94 | if (target.callback) { 95 | target.callback(); 96 | } 97 | }; 98 | } 99 | if (target.checkCallback) { 100 | command.checkCallback = (checking) => { 101 | const target = app.commands.commands[alias.commandId]; 102 | if (!target) { 103 | if (checking) { 104 | // Don't hide the probrem. 105 | return true; 106 | } 107 | new Notice("Missing command. The command may be invalid."); 108 | return; 109 | } 110 | if (target.checkCallback) { 111 | return target.checkCallback(checking); 112 | } 113 | } 114 | } 115 | this.addCommand(command); 116 | }).catch((reason) => { 117 | // fallback 118 | const command: Command = { 119 | id: `alias:${aliasId}`, 120 | name: `${alias.name}: Missing command. Run this and try rebinding.`, 121 | callback: () => { 122 | this.unload(); 123 | this.load(); 124 | } 125 | } 126 | this.addCommand(command); 127 | }); 128 | 129 | return commandDetection; 130 | } 131 | 132 | onunload() { 133 | } 134 | 135 | async loadSettings() { 136 | this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); 137 | } 138 | 139 | async saveSettings() { 140 | await this.saveData(this.settings); 141 | } 142 | 143 | addAliasSetting(aliasName: string, commandId: string) { 144 | const aliasId = Date.now().toString(); 145 | // console.log('Add id:', aliasId, 'alias:', aliasName, "command:", commandId); 146 | this.settings.aliases[aliasId] = { 147 | name: aliasName, 148 | commandId: commandId, 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/setting-tab.ts: -------------------------------------------------------------------------------- 1 | import { App, PluginSettingTab, Setting } from "obsidian"; 2 | import { AppExtension } from "./uncover-obsidian"; 3 | import CommandAliasPlugin from "./main"; 4 | 5 | export class CommandAliasPluginSettingTab extends PluginSettingTab { 6 | plugin: CommandAliasPlugin; 7 | 8 | constructor(app: App, plugin: CommandAliasPlugin) { 9 | super(app, plugin); 10 | this.plugin = plugin; 11 | } 12 | 13 | display(): void { 14 | const { containerEl } = this; 15 | 16 | const app = this.app as AppExtension; 17 | const options: Record = { "": "--- command list ---" }; 18 | for (const key in app.commands.commands) { 19 | if (!Object.prototype.hasOwnProperty.call(app.commands.commands, key)) { 20 | continue; 21 | } 22 | if (key.startsWith('obsidian-command-alias-plugin:')) { 23 | continue; 24 | } 25 | 26 | const command = app.commands.commands[key]; 27 | options[key] = command.name; 28 | } 29 | 30 | 31 | containerEl.empty(); 32 | 33 | containerEl.createEl('h2', { text: 'Command alias' }); 34 | 35 | // command detection 36 | containerEl.createEl('h3', { text: 'Command detection' }); 37 | new Setting(containerEl) 38 | .setName('Maximum number of trials') 39 | .addSlider(slider => slider 40 | .setLimits(1, 10, 1) 41 | .setValue(this.plugin.settings.commandDetection.maxTry) 42 | .setDynamicTooltip() 43 | .onChange(async value => { 44 | this.plugin.settings.commandDetection.maxTry = value; 45 | await this.plugin.saveSettings(); 46 | }) 47 | ); 48 | new Setting(containerEl) 49 | .setName('Trial interval (msec)') 50 | .addSlider(slider => slider 51 | .setLimits(100, 1000, 100) 52 | .setValue(this.plugin.settings.commandDetection.msecOfInterval) 53 | .setDynamicTooltip() 54 | .onChange(async value => { 55 | this.plugin.settings.commandDetection.msecOfInterval = value; 56 | await this.plugin.saveSettings(); 57 | }) 58 | ); 59 | 60 | // remove alias 61 | containerEl.createEl('h3', { text: 'Register aliases' }); 62 | 63 | type RemoveAliasUnit = { 64 | aliasId: string, 65 | aliasName: string, 66 | commandName: string, 67 | } 68 | const aliasesForRemove: RemoveAliasUnit[] = []; 69 | for (const aliasId in this.plugin.settings.aliases) { 70 | if (!Object.prototype.hasOwnProperty.call(this.plugin.settings.aliases, aliasId)) { 71 | continue; 72 | } 73 | const alias = this.plugin.settings.aliases[aliasId]; 74 | const aliasName = alias.name; 75 | const command = app.commands.commands[alias.commandId]; 76 | const commandName = (command && command.name) || 'command missing'; 77 | aliasesForRemove.push({ 78 | aliasId, 79 | aliasName, 80 | commandName, 81 | }); 82 | } 83 | 84 | aliasesForRemove.sort((a, b) => { 85 | if (a.aliasName < b.aliasName) { 86 | return -1; 87 | } 88 | if (a.aliasName > b.aliasName) { 89 | return 1; 90 | } 91 | return 0; 92 | }); 93 | 94 | // Render settings 95 | for (const { aliasId, aliasName, commandName } of aliasesForRemove) { 96 | 97 | new Setting(containerEl) 98 | .setName(aliasName) 99 | .setDesc(commandName) 100 | .addButton(button => button 101 | .setButtonText('Remove') 102 | .onClick(async e => { 103 | delete this.plugin.settings.aliases[aliasId]; 104 | await this.plugin.saveSettings(); 105 | this.display(); 106 | })); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/uncover-obsidian.ts: -------------------------------------------------------------------------------- 1 | import { App, Command } from "obsidian"; 2 | 3 | export class AppExtension extends App { 4 | commands: { 5 | commands: CommandMap 6 | } 7 | } 8 | 9 | type CommandMap = { 10 | [key: string]: Command; 11 | } 12 | -------------------------------------------------------------------------------- /styles.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yajamon/obsidian-command-alias-plugin/e453c96893f7a12d806627148c79f5caa2a04280/styles.css -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "inlineSourceMap": true, 5 | "inlineSources": true, 6 | "module": "ESNext", 7 | "target": "ES6", 8 | "allowJs": true, 9 | "noImplicitAny": true, 10 | "moduleResolution": "node", 11 | "importHelpers": true, 12 | "isolatedModules": true, 13 | "strictNullChecks": true, 14 | "lib": [ 15 | "DOM", 16 | "ES5", 17 | "ES6", 18 | "ES7" 19 | ] 20 | }, 21 | "include": [ 22 | "**/*.ts" 23 | ], 24 | "exclude": [ 25 | "**/*.test.ts" 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /versions.json: -------------------------------------------------------------------------------- 1 | { 2 | "1.0.0": "0.9.12", 3 | "1.0.1": "0.9.12", 4 | "2.0.0": "0.9.12", 5 | "2.0.1": "0.15.0" 6 | } 7 | --------------------------------------------------------------------------------