magic-enter.plugin.zsh 636 B

123456789101112131415161718192021222324
  1. # Bind quick stuff to enter!
  2. #
  3. # Pressing enter in a git directory runs `git status`
  4. # in other directories `ls`
  5. magic-enter () {
  6. # If commands are not already set, use the defaults
  7. [ -z "$MAGIC_ENTER_GIT_COMMAND" ] && MAGIC_ENTER_GIT_COMMAND="git status -u ."
  8. [ -z "$MAGIC_ENTER_OTHER_COMMAND" ] && MAGIC_ENTER_OTHER_COMMAND="ls -lh ."
  9. if [[ -z $BUFFER ]]; then
  10. echo ""
  11. if git rev-parse --is-inside-work-tree &>/dev/null; then
  12. eval "$MAGIC_ENTER_GIT_COMMAND"
  13. else
  14. eval "$MAGIC_ENTER_OTHER_COMMAND"
  15. fi
  16. zle redisplay
  17. else
  18. zle accept-line
  19. fi
  20. }
  21. zle -N magic-enter
  22. bindkey "^M" magic-enter