How to make an alias for a keyboard shortcut/hotke

2019-06-10 16:14发布

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"

1条回答
等我变得足够好
2楼-- · 2019-06-10 17:21

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.

查看更多
登录 后发表回答