0

I'm trying to setup an alias in OS X that will be run by a keyboard shortcut or hotkey. Is this possible?

alias newtab = "command+t"
Tim
  • 41,901
  • 18
  • 127
  • 145
Rich
  • 1,136
  • 3
  • 16
  • 36
  • 2
    A keyboard shortcut will run a command. Just find out what command that is and use it as your alias. – arco444 Apr 17 '15 at 13:52
  • 1
    @arco444 While somewhat true that isn't necessarily at the level the shell can deal with (i.e. an application internal shortcut isn't running a "command" the shell can execute). – Etan Reisner Apr 17 '15 at 13:54
  • @arco444 any thoughts on how I can determine what command is being run when a shortcut is run? – Rich Apr 17 '15 at 13:58
  • 2
    something like this? [Open a new tab in gnome-terminal using command line](http://stackoverflow.com/questions/1188959/open-a-new-tab-in-gnome-terminal-using-command-line) ..... but in OS X – Jose Ricardo Bustos M. Apr 17 '15 at 13:58
  • @Rich as Etan points out that really depends on what application you're trying to use it in... If the application allows you to configure hotkeys that might be the place to start – arco444 Apr 17 '15 at 14:01

1 Answers1

0

to determine which command is run by a Zsh keybinding, you should use describe-key-briefly. Which IIRC in emacs mode is assigned to ^hk (control-H and then k). So you would type ^Hk and after that whichever keybinding you wish to inspect. Example ^hk ^r

To see all your bindings, just call bindkey without any arguments.

[...]

Now to answer your original question. To bind a Zsh function to a (shell) key binding, you should define a function that does whatever you want (not an alias...)

function hello() { echo "hello... I am running..." }
zle -N hello
bindkey "^hh" hello

now when you type ^hh you will run that function. See the manual for zle and bindkey.

Francisco
  • 3,980
  • 1
  • 23
  • 27