Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: Don't use =~ for simple prefix match



On Mon, Mar 6, 2017, at 06:18 PM, Mikael Magnusson wrote:
> -    if [[ "${OSTYPE}" =~ freebsd.* ]]; then
> +    if [[ "${OSTYPE}" = freebsd* ]]; then

Did similar for _hosts:

-            elif [[ $host =~ "\[(.*)\]:\d*" ]]; then
-              khosts+=$match
+            elif [[ $host = (#b)*\[(*)\]:[[:digit:]]#* ]]; then
+              khosts+=${match[1]}

Also localized match parameters.

Had to add wrapping stars because =~ matches substrings.
-- 
  Sebastian Gniazdowski
  psprint3@xxxxxxxxxxxx
diff --git a/Completion/Unix/Type/_hosts b/Completion/Unix/Type/_hosts
index 5654086..d9e1090 100644
--- a/Completion/Unix/Type/_hosts
+++ b/Completion/Unix/Type/_hosts
@@ -50,12 +50,13 @@ if ! zstyle -a ":completion:${curcontext}:hosts" hosts _hosts; then
         # entries.
         () {
           local host
+          local -a match mbegin mend
           khosts=()
           for host; do
             if [[ $host == *[*?]* ]]; then
               continue
-            elif [[ $host =~ "\[(.*)\]:\d*" ]]; then
-              khosts+=$match
+            elif [[ $host = (#b)*\[(*)\]:[[:digit:]]#* ]]; then
+              khosts+=${match[1]}
             else
               khosts+=$host
             fi


Messages sorted by: Reverse Date, Date, Thread, Author