From 82856bfbd86ac77f0f28ab741a399a04495ed3bc Mon Sep 17 00:00:00 2001 From: VectorW <15570764+VectorWpl@users.noreply.github.com> Date: Sun, 11 Oct 2020 21:23:21 +0200 Subject: globalias: allow filtering values not to be expanded (#9331) --- plugins/globalias/README.md | 19 ++++++++++++++++++- plugins/globalias/globalias.plugin.zsh | 6 ++++-- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'plugins/globalias') diff --git a/plugins/globalias/README.md b/plugins/globalias/README.md index 0b064105d..cd7fc3cb2 100644 --- a/plugins/globalias/README.md +++ b/plugins/globalias/README.md @@ -17,6 +17,9 @@ 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`. +if you would like to filter out any values from expanding set `GLOBALIAS_FILTER_VALUES` to +an array of said values. See [Filtered values](#filtered-values). + ## Examples #### Glob expressions @@ -37,7 +40,6 @@ $ ls folder/file.json anotherfolder/another.json $ mkdir "`date -R`" # expands to $ mkdir Tue,\ 04\ Oct\ 2016\ 13:54:03\ +0300 - ``` #### Aliases @@ -60,3 +62,18 @@ $ S # expands to: $ sudo systemctl ``` + +#### Filtered values + +``` +# .zshrc +alias l='ls -lh' +alias la='ls --color=auto -lah' +GLOBALIAS_FILTER_VALUES=(l) + +$ l +# does not expand +$ la +# expands to: +$ ls --color=auto -lah +``` diff --git a/plugins/globalias/globalias.plugin.zsh b/plugins/globalias/globalias.plugin.zsh index 9602a9606..f8c07ce43 100644 --- a/plugins/globalias/globalias.plugin.zsh +++ b/plugins/globalias/globalias.plugin.zsh @@ -1,6 +1,8 @@ globalias() { - zle _expand_alias - zle expand-word + if [[ $GLOBALIAS_FILTER_VALUES[(Ie)$LBUFFER] -eq 0 ]]; then + zle _expand_alias + zle expand-word + fi zle self-insert } zle -N globalias -- cgit v1.2.3-70-g09d2 From e75aa2875eea94fcf7ceb3f246db96cc3bc61a2e Mon Sep 17 00:00:00 2001 From: "Patrick W. Healy" Date: Wed, 14 Oct 2020 09:57:59 -0500 Subject: globalias: expand filtering to anywhere in the command (#9338) --- plugins/globalias/globalias.plugin.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'plugins/globalias') diff --git a/plugins/globalias/globalias.plugin.zsh b/plugins/globalias/globalias.plugin.zsh index f8c07ce43..d4d40c863 100644 --- a/plugins/globalias/globalias.plugin.zsh +++ b/plugins/globalias/globalias.plugin.zsh @@ -1,5 +1,7 @@ globalias() { - if [[ $GLOBALIAS_FILTER_VALUES[(Ie)$LBUFFER] -eq 0 ]]; then + # Get last word to the left of the cursor + local word=${${(A)=LBUFFER}[-1]} + if [[ $GLOBALIAS_FILTER_VALUES[(Ie)$word] -eq 0 ]]; then zle _expand_alias zle expand-word fi -- cgit v1.2.3-70-g09d2 From 53cbd658f5ae6874af0d804cee6748dfba69e786 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 14 Oct 2020 17:23:03 +0200 Subject: globalias: use ${(z)var} to split into words using shell parsing --- plugins/globalias/globalias.plugin.zsh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'plugins/globalias') diff --git a/plugins/globalias/globalias.plugin.zsh b/plugins/globalias/globalias.plugin.zsh index d4d40c863..bd27d589d 100644 --- a/plugins/globalias/globalias.plugin.zsh +++ b/plugins/globalias/globalias.plugin.zsh @@ -1,6 +1,8 @@ globalias() { - # Get last word to the left of the cursor - local word=${${(A)=LBUFFER}[-1]} + # Get last word to the left of the cursor: + # (z) splits into words using shell parsing + # (A) makes it an array even if there's only one element + local word=${${(Az)LBUFFER}[-1]} if [[ $GLOBALIAS_FILTER_VALUES[(Ie)$word] -eq 0 ]]; then zle _expand_alias zle expand-word -- cgit v1.2.3-70-g09d2