Bash – Bindkey to execute command (Zsh)

bashkeyboard shortcutsreadlineshellzlezsh

In one can do the following:

bind -x '"\C-l":ls'

to map Ctrl+L to external (ie. system's rather than function)

ls command to list directory contents.

How to do the same in , and preferably with Alt (\M-l?)

instead of Ctrl as it is seemingly already bound to clear to clear the screen.

Best Answer

% namingthingsishard () { echo; ls; zle redisplay }
% zle -N namingthingsishard                  
% bindkey '^l' namingthingsishard                  
% 

This binds control+l because I don't know what \M-l generates for you; running read -r and then mashing keys might show something suitable to use with bindkey, or run bindkey with no arguments to show what is already set. For more information on bindkey and widgets, see zshzle(1).