Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active August 26, 2018 08:33
Show Gist options
  • Save YumaInaura/64299ac1e74d3cd1c722fcd38751f63d to your computer and use it in GitHub Desktop.
Save YumaInaura/64299ac1e74d3cd1c722fcd38751f63d to your computer and use it in GitHub Desktop.
Zsh — Very beginner of bindkey ( Since today you are zle master )

Zsh — Very beginner of bindkey ( Since today you are zle master )

Points

You don't need any script file to check bindkey behaviour.

Just hit keys and binding.

You can reset all bindkeys by bindkey -d or restart shell ( e.g exec $SHELL or close window and reopen windows )

Bind string

bindkey -s A "some string"

Hit capital letter "A" key and some string appears.

Bind zle widget

bindkey B accept-line

Push B key and Enter happens and.

"accept-line" is zle basic widget.

Show all bindkey mappings

bindkey

Enter with no arguments.

You will see all bindkey mappings and zle widgets list.

"^@" set-mark-command
"^A" beginning-of-line
"^B" backward-char
"^D" delete-char-or-list
"^E" incremental-select-command-history
...

Bind custom widget by shell function

Defune shell function.

function _hello_zle(){ echo "Hello zle original widget" && zle reset-prompt }

by zle command.

zle -N hello _hello_zle
bindkey C hello
# Push C
Hello zle custom widget!

Overwrite widget behaviour

Overwrite shell function overwrites widget behaviour.

function _hello_zle(){ echo "Umm comfortable zsh" && zle reset-prompt }
# Push C
Umm comfortable zsh

Versions

  • zsh 5.5.1 (x86_64-apple-darwin17.5.0)

Ref

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment