From 798c38dd1a70637cd17c26879be83e7f25a3ee53 Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Tue, 27 Sep 2016 15:18:23 +0300 Subject: [PATCH 1/5] globalias fix #4834 --- plugins/globalias/globalias.plugin.zsh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 plugins/globalias/globalias.plugin.zsh diff --git a/plugins/globalias/globalias.plugin.zsh b/plugins/globalias/globalias.plugin.zsh new file mode 100644 index 00000000..95a0e307 --- /dev/null +++ b/plugins/globalias/globalias.plugin.zsh @@ -0,0 +1,11 @@ +globalias() { + zle _expand_alias + zle expand-word + zle self-insert +} +zle -N globalias +bindkey -e " " globalias +bindkey -v " " globalias +bindkey -e "^ " magic-space # control-space to bypass completion +bindkey -v "^ " magic-space +bindkey -M isearch " " magic-space # normal space during searches From 86126233bb5bb99ced64b95c16a4e4ed776fd8de Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Tue, 4 Oct 2016 12:21:18 +0300 Subject: [PATCH 2/5] specify globalias modes --- plugins/globalias/globalias.plugin.zsh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/globalias/globalias.plugin.zsh b/plugins/globalias/globalias.plugin.zsh index 95a0e307..bac657c4 100644 --- a/plugins/globalias/globalias.plugin.zsh +++ b/plugins/globalias/globalias.plugin.zsh @@ -4,8 +4,11 @@ globalias() { zle self-insert } zle -N globalias -bindkey -e " " globalias -bindkey -v " " globalias -bindkey -e "^ " magic-space # control-space to bypass completion -bindkey -v "^ " magic-space -bindkey -M isearch " " magic-space # normal space during searches + +# space expands all global aliases +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 From 75f87dd24ec60bd243ffbe7c9dbd1daec5b51ae2 Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Tue, 4 Oct 2016 14:03:37 +0300 Subject: [PATCH 3/5] README for globalias --- plugins/globalias/README.md | 37 ++++++++++++++++++++++++++ plugins/globalias/globalias.plugin.zsh | 3 +++ 2 files changed, 40 insertions(+) create mode 100644 plugins/globalias/README.md diff --git a/plugins/globalias/README.md b/plugins/globalias/README.md new file mode 100644 index 00000000..db2e5bee --- /dev/null +++ b/plugins/globalias/README.md @@ -0,0 +1,37 @@ +#Globalias + + +Expands all globes, backtick expressions and aliases(including global). + +``` +$ touch {1..10} +#expands to +$ touch 1 2 3 4 5 6 7 8 9 10 + +$ mkdir "`date -R`" +#expands to +$ mkdir Tue,\ 04\ Oct\ 2016\ 13:54:03\ +0300 + +#.zshrc: +alias -g G="| grep --color=auto -P" +alias l='ls --color=auto -lah' + +$ lG +#expands to +$ ls --color=auto -lah | grep --color=auto -P + +ls **/*.json +#expands to +ls folder/file.json anotherfolder/another.json +``` + +####Returns autocompletion to your custom aliases: +``` +#.zsrc +alias S="sudo systemctl" + +$ S +#expands to: +sudo systemctl s +#trigger autocompletion +``` diff --git a/plugins/globalias/globalias.plugin.zsh b/plugins/globalias/globalias.plugin.zsh index bac657c4..bf4cfc03 100644 --- a/plugins/globalias/globalias.plugin.zsh +++ b/plugins/globalias/globalias.plugin.zsh @@ -12,3 +12,6 @@ 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 From 6eaa868cd9ad8447973a53f09453121d58366a6a Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Tue, 4 Oct 2016 14:05:41 +0300 Subject: [PATCH 4/5] fix comment --- plugins/globalias/globalias.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/globalias/globalias.plugin.zsh b/plugins/globalias/globalias.plugin.zsh index bf4cfc03..9602a960 100644 --- a/plugins/globalias/globalias.plugin.zsh +++ b/plugins/globalias/globalias.plugin.zsh @@ -5,7 +5,7 @@ globalias() { } zle -N globalias -# space expands all global aliases +# space expands all aliases, including global bindkey -M emacs " " globalias bindkey -M viins " " globalias From f701b4de0fb55b71e2cfb17522a08fba741ff170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 4 Oct 2016 13:55:11 +0200 Subject: [PATCH 5/5] Fix formatting and usage section Also: - Changes `globes` (which doesn't exist) to `glob expressions`. - Delete the `trigger autocompletion to your current aliases` use case, since that's not really implemented. --- plugins/globalias/README.md | 55 +++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/plugins/globalias/README.md b/plugins/globalias/README.md index db2e5bee..ba9888cc 100644 --- a/plugins/globalias/README.md +++ b/plugins/globalias/README.md @@ -1,37 +1,62 @@ -#Globalias +# Globalias plugin +Expands all glob expressions, subcommands and aliases (including global). -Expands all globes, backtick expressions 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} -#expands to +# expands to $ touch 1 2 3 4 5 6 7 8 9 10 +$ ls **/*.json +# expands to +$ ls folder/file.json anotherfolder/another.json +``` + +#### Subcommands + +``` $ mkdir "`date -R`" -#expands to +# expands to $ mkdir Tue,\ 04\ Oct\ 2016\ 13:54:03\ +0300 -#.zshrc: +``` + +#### Aliases + +``` +# .zshrc: alias -g G="| grep --color=auto -P" alias l='ls --color=auto -lah' $ lG -#expands to +# expands to $ ls --color=auto -lah | grep --color=auto -P - -ls **/*.json -#expands to -ls folder/file.json anotherfolder/another.json ``` -####Returns autocompletion to your custom aliases: ``` -#.zsrc +# .zsrc: alias S="sudo systemctl" $ S -#expands to: -sudo systemctl s -#trigger autocompletion +# expands to: +$ sudo systemctl ```