82856bfbd86ac77f0f28ab741a399a04495ed3bc

Author
VectorW <15570764+VectorWpl@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

globalias: allow filtering values not to be expanded (#9331)

Diff

 1diff --git a/plugins/globalias/README.md b/plugins/globalias/README.md
 2index 0b064105dbb6b0f161ad6019b8dfa6e997f279b6..cd7fc3cb2d432cfee2e5ed2e9ebf2ac863472eca 100644
 3--- a/plugins/globalias/README.md
 4+++ b/plugins/globalias/README.md
 5@@ -17,6 +17,9 @@ Then just press `SPACE` to trigger the expansion of a command you've written.
 6 If you only want to insert a space without expanding the command line, press
 7 `CTRL`+`SPACE`.
 8 
 9+if you would like to filter out any values from expanding set `GLOBALIAS_FILTER_VALUES` to
10+an array of said values. See [Filtered values](#filtered-values).
11+
12 ## Examples
13 
14 #### Glob expressions
15@@ -37,7 +40,6 @@ $ ls folder/file.json anotherfolder/another.json
16 $ mkdir "`date -R`"
17 # expands to
18 $ mkdir Tue,\ 04\ Oct\ 2016\ 13:54:03\ +0300
19-
20 ```
21 
22 #### Aliases
23@@ -60,3 +62,18 @@ $ S<space>
24 # expands to:
25 $ sudo systemctl
26 ```
27+
28+#### Filtered values
29+
30+```
31+# .zshrc
32+alias l='ls -lh'
33+alias la='ls --color=auto -lah'
34+GLOBALIAS_FILTER_VALUES=(l)
35+
36+$ l<space>
37+# does not expand
38+$ la<space>
39+# expands to:
40+$ ls --color=auto -lah
41+```
42diff --git a/plugins/globalias/globalias.plugin.zsh b/plugins/globalias/globalias.plugin.zsh
43index 9602a96061560d3833836f73d7901857aaed108f..f8c07ce4356160ec536343f3f3975f7a3ef9899b 100644
44--- a/plugins/globalias/globalias.plugin.zsh
45+++ b/plugins/globalias/globalias.plugin.zsh
46@@ -1,6 +1,8 @@
47 globalias() {
48-   zle _expand_alias
49-   zle expand-word
50+   if [[ $GLOBALIAS_FILTER_VALUES[(Ie)$LBUFFER] -eq 0 ]]; then
51+      zle _expand_alias
52+      zle expand-word
53+   fi
54    zle self-insert
55 }
56 zle -N globalias