2 : ${MAGIC_ENTER_GIT_COMMAND:="git status -u ."} # run when in a git repository
3 : ${MAGIC_ENTER_OTHER_COMMAND:="ls -lh ."} # run anywhere else
6 # Only run MAGIC_ENTER commands when in PS1 and command line is empty
7 # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#User_002dDefined-Widgets
8 if [[ -n "$BUFFER" || "$CONTEXT" != start ]]; then
12 if command git rev-parse --is-inside-work-tree &>/dev/null; then
13 BUFFER="$MAGIC_ENTER_GIT_COMMAND"
15 BUFFER="$MAGIC_ENTER_OTHER_COMMAND"
19 # Wrapper for the accept-line zle widget (run when pressing Enter)
21 # If the wrapper already exists don't redefine it
22 (( ! ${+functions[_magic-enter_accept-line]} )) || return 0
24 case "$widgets[accept-line]" in
25 # Override the current accept-line widget, calling the old one
26 user:*) zle -N _magic-enter_orig_accept-line "${widgets[accept-line]#user:}"
27 function _magic-enter_accept-line() {
29 zle _magic-enter_orig_accept-line -- "$@"
31 # If no user widget defined, call the original accept-line widget
32 builtin) function _magic-enter_accept-line() {
38 zle -N accept-line _magic-enter_accept-line