From bf1eadbb79280655d537cc01277aef1edd272001 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Fri, 3 Jun 2022 14:49:42 +0200 Subject: [PATCH] zsh:funcs:suffix: Fix multiple suffixes While trying to handle whitespace in the suffixes the support for passing multiple suffixes broke. This should now support multiple suffixes as well as included whitespaces. --- .config/zsh/zshrc.d/40-functions.zsh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.config/zsh/zshrc.d/40-functions.zsh b/.config/zsh/zshrc.d/40-functions.zsh index b35f570..6c34a8d 100644 --- a/.config/zsh/zshrc.d/40-functions.zsh +++ b/.config/zsh/zshrc.d/40-functions.zsh @@ -553,5 +553,13 @@ suffix() { # NOTE: if "--" is not included in $@, i will be greater than $#, and no # starting point is passed to `find`, which then defaults to `.`. - find "${@:$((i+1))}" -name "*${(@j: -o -name *:)@:1:$((i-1))}" + local -a names + # Take everything before "--" + names=( "${@:1:$((i-1))}" ) + # Prepend an `*` to every element and quote the result + names=( "${(@)names//(#b)(*)/\"*$match\"}") + # Join with " -o -name " and then split again using shell parsing + names=( "${(@zj: -o -name :)names}" ) + # Pass starting points and the names after removing one level of quotes + find "${@:$((i+1))}" -name "${(@Q)names}" }