-
Notifications
You must be signed in to change notification settings - Fork 0
Overriding Default Commands
Place your command overriding code in the file:
~/voicecode/commando/user/commands.coffee
Or if that file is getting too busy, create another file in the same directory, maybe named: 'overrides.coffee'
Sometimes you want to change the default commands to do something your own way. A good example would be for German keyboard-layout users, since that layout switches the 'Z' and 'Y' keys. If you wanted to change the 'dizzle' command to press command-Y instead of command-Z you could do the following:
CoffeeScript
Commands.override "dizzle", (input, original) ->
@key "Y", ['command']JavaScript
Commands.override("dizzle", function(input, original) {
this.key("Y", ['command']);
});Other times you want to keep the default action, but "wrap" your own code around the defaults. To do this you could do something like:
CoffeeScript
Commands.override "snake", (input, original) ->
console.log "starting the snake command"
original.call(@)
console.log "finished the snake command"JavaScript
Commands.override("snake", function(input, original) {
console.log("starting the snake command");
original.call(this);
console.log("finished the snake command");
});Sometimes you want to extend an existing command. You could completely over-write the command's 'action' function, but then if the underlying command changed in a future update, that update would not trickle into your extended version. Instead, you can override the command and call the 'original' command from within your overridden function. For example, imagine if whenever I used the "shackle" command to select an entire line of text, I also wanted to perform a "copy" keystroke afterwards, but only if I am in the Mail application. I could do this:
Commands.override "shackle", (input, original) ->
original.call(@)
if @currentApplication() is "Mail"
@key "C", ['command']You can get as fancy as you want with these overrides so that VoiceCode gets tailored to your specific workflows and use-cases.
Occasionally you may have some reason to change the name of a built-in command. To achieve this, simply do:
Commands.changeName "old name", "new name"