summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Cornellà <marc.cornella@live.com>2016-10-04 14:50:28 +0200
committerGitHub <noreply@github.com>2016-10-04 14:50:28 +0200
commit7f06a0cd8238747277130334c264b7a679403ba4 (patch)
treeafdad993584cd89c3db20527aacf43ceae4a6e27
parent3cc61701bd7fd0a3fa6cb3c70f2b927a1e51970a (diff)
parentf701b4de0fb55b71e2cfb17522a08fba741ff170 (diff)
downloadzsh-7f06a0cd8238747277130334c264b7a679403ba4.tar.gz
zsh-7f06a0cd8238747277130334c264b7a679403ba4.tar.bz2
zsh-7f06a0cd8238747277130334c264b7a679403ba4.zip
Merge pull request #5463 from slavaGanzin/globalias
Fixes #4834
-rw-r--r--plugins/globalias/README.md62
-rw-r--r--plugins/globalias/globalias.plugin.zsh17
2 files changed, 79 insertions, 0 deletions
diff --git a/plugins/globalias/README.md b/plugins/globalias/README.md
new file mode 100644
index 000000000..ba9888ccb
--- /dev/null
+++ b/plugins/globalias/README.md
@@ -0,0 +1,62 @@
+# Globalias plugin
+
+Expands all glob expressions, subcommands and aliases (including global).
+
+Idea from: http://blog.patshead.com/2012/11/automatically-expaning-zsh-global-aliases---simplified.html.
+
+## Usage
+
+Add `globalias` to the plugins array in your zshrc file:
+
+```zsh
+plugins=(... globalias)
+```
+
+Then just press `SPACE` to trigger the expansion of a command you've written.
+
+If you only want to insert a space without expanding the command line, press
+`CTRL`+`SPACE`.
+
+## Examples
+
+#### Glob expressions
+
+```
+$ touch {1..10}<space>
+# expands to
+$ touch 1 2 3 4 5 6 7 8 9 10
+
+$ ls **/*.json<space>
+# expands to
+$ ls folder/file.json anotherfolder/another.json
+```
+
+#### Subcommands
+
+```
+$ mkdir "`date -R`"
+# expands to
+$ mkdir Tue,\ 04\ Oct\ 2016\ 13:54:03\ +0300
+
+```
+
+#### Aliases
+
+```
+# .zshrc:
+alias -g G="| grep --color=auto -P"
+alias l='ls --color=auto -lah'
+
+$ l<space>G<space>
+# expands to
+$ ls --color=auto -lah | grep --color=auto -P
+```
+
+```
+# .zsrc:
+alias S="sudo systemctl"
+
+$ S<space>
+# expands to:
+$ sudo systemctl
+```
diff --git a/plugins/globalias/globalias.plugin.zsh b/plugins/globalias/globalias.plugin.zsh
new file mode 100644
index 000000000..9602a9606
--- /dev/null
+++ b/plugins/globalias/globalias.plugin.zsh
@@ -0,0 +1,17 @@
+globalias() {
+ zle _expand_alias
+ zle expand-word
+ zle self-insert
+}
+zle -N globalias
+
+# space expands all aliases, including global
+bindkey -M emacs " " globalias
+bindkey -M viins " " globalias
+
+# control-space to make a normal space
+bindkey -M emacs "^ " magic-space
+bindkey -M viins "^ " magic-space
+
+# normal space during searches
+bindkey -M isearch " " magic-space