Add magic-enter plugin (#4082)
* Added magic-enter plugin
To bind commonly used tasks to the enter key
* Allow the magic-enter commands to be modified by the user
Diff
1diff --git a/plugins/magic-enter/Readme.md b/plugins/magic-enter/Readme.md
2new file mode 100644
3index 0000000000000000000000000000000000000000..b401ab415d0e3ea68c91fd931354c393a7a42630
4--- /dev/null
5+++ b/plugins/magic-enter/Readme.md
6@@ -0,0 +1,14 @@
7+## Magic Enter
8+
9+**Maintainer:** [@dufferzafar](https://github.com/dufferzafar)
10+
11+Makes your enter key magical, by binding commonly used commands to it.
12+
13+You can set the commands to be run in your .zshrc, before the line containing plugins!
14+
15+```bash
16+MAGIC_ENTER_GIT_COMMAND='git status -u .'
17+MAGIC_ENTER_OTHER_COMMAND='ls -lh .'
18+
19+plugins=(magic-enter)
20+```
21diff --git a/plugins/magic-enter/magic-enter.plugin.zsh b/plugins/magic-enter/magic-enter.plugin.zsh
22new file mode 100644
23index 0000000000000000000000000000000000000000..8e1859678b194711ef480cc39f107df7bbf0e7d8
24--- /dev/null
25+++ b/plugins/magic-enter/magic-enter.plugin.zsh
26@@ -0,0 +1,24 @@
27+# Bind quick stuff to enter!
28+#
29+# Pressing enter in a git directory runs `git status`
30+# in other directories `ls`
31+magic-enter () {
32+
33+ # If commands are not already set, use the defaults
34+ [ -z "$MAGIC_ENTER_GIT_COMMAND" ] && MAGIC_ENTER_GIT_COMMAND="git status -u ."
35+ [ -z "$MAGIC_ENTER_OTHER_COMMAND" ] && MAGIC_ENTER_OTHER_COMMAND="ls -lh ."
36+
37+ if [[ -z $BUFFER ]]; then
38+ echo ""
39+ if git rev-parse --is-inside-work-tree &>/dev/null; then
40+ eval "$MAGIC_ENTER_GIT_COMMAND"
41+ else
42+ eval "$MAGIC_ENTER_OTHER_COMMAND"
43+ fi
44+ zle redisplay
45+ else
46+ zle accept-line
47+ fi
48+}
49+zle -N magic-enter
50+bindkey "^M" magic-enter