linux - ZSH: Behavior on Enter -


i realize, when i'm in terminal, expect press enter on empty input make ls or git status when i'm on git repos.

how can achieve that? mean, have custom behavior on empty input -> enter in zsh?


edit: help. here's take preexec...

precmd() {   echo $0;   if ["${0}" -eq ""];     if [ -d .git ];       git status     else       ls     fi;   else     $1   fi; } 

on enter zsh calls accept-line widget, causes buffer executed command.

you can write own widget in order implement behaviour want , rebind enter:

my-accept-line () {     # check if buffer not contain words     if [ ${#${(z)buffer}} -eq 0 ];         # put newline output not start next         # prompt         echo         # check if inside git repository         if git rev-parse --git-dir > /dev/null 2>&1 ;             # if so, execute `git status'             git status         else             # else run `ls'             ls         fi     fi     # in case run `accept-line' widget     zle accept-line } # create widget `my-accept-line' same name zle -n my-accept-line # rebind enter, `^m' bindkey '^m' my-accept-line 

while sufficient run zle accept-line in cases there command, zsh not put new prompt after output. , while possible redraw prompt zle redisplay, overwrite last line(s) of output if using multi-line prompts. (of course there workarounds that, too, nothing simple using zle accept-line.

warning: redfines (the most?) essential part of shell. while there nothing wrong per se (else not have posted here), has real chance make shell unusable if my-accept-line not run flawlessly. example, if zle accept-line missing, not use enter confirm command (e.g. redefine my-accept-line or start editor). please, test before putting ~/.zshrc.

also, default accept-line bound ctrl+j, too. recommend leave way, have easy way run default accept-line.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -