From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id c5115239 for ; Sun, 17 Mar 2019 02:56:32 +0000 (UTC) Received: (qmail 14104 invoked by alias); 17 Mar 2019 02:56:14 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23877 Received: (qmail 20881 invoked by uid 1010); 17 Mar 2019 02:56:14 -0000 X-Qmail-Scanner-Diagnostics: from mail-oi1-f179.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.100.2/25384. spamassassin: 3.4.2. Clear:RC:0(209.85.167.179):SA:0(-2.0/5.0):. Processed in 1.996169 secs); 17 Mar 2019 02:56:14 -0000 X-Envelope-From: sgniazdowski@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.167.179 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=VO15GqwtLfSSmyF68HYYvPvPHzCYLXFFHN3TamUFTlE=; b=qFU0nF8zFCjhl6fsaMNAYrogi2oqDTke2Zhv0ChMpbDY2Mz4wNhOWNNVuK33LOW+lF FrjMAEw6qI9CDXMT4SURhfaaKNjYLICiFGCXID6SEVutmqq3+QXz7SWKOTx+jE8A4fMS WEc1gDH+ydiRyXOw6iI5egNgGX9A9Ed8uqGvNXqpcyZ/B4W2Yh0ymA/fhwec5YQX6pkJ VvkFfFtFnlqkj1f0V/jJRvIQrQXdi0WQroRHii2orW1sYvmCDNH8Y/Qb61EREoXOYrKU 9BZa1Gr9g3Bq/NGuQan04sFCU+HQCFMjMWIxiImpQJGq9yUEuKm6Z0eKjqA40LFEL6GC jBnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=VO15GqwtLfSSmyF68HYYvPvPHzCYLXFFHN3TamUFTlE=; b=BX5T+xpOeXWDGqMbCBI/hPVigvTWd3j4vrxn28PLf0AW2S2S/ZTV5q0v4hhNpQjLx1 LIAgM5dtVorLb1oNxdVRPRZLdnCW3g/Zb2E7W6O1bDKiAq/wBp6m1qA5LWa43+DEjGC8 R+vwmcb/yuKlKoa+10zHuGpc5DBNXdvHJ6cDly6szqgh5wiX5gURqj4ZY5TWE9/4/aj3 +uydd8f2gEHnsrMYUuRaCrPEyQEoZZvWl8YD03z2TtA7ThtnBcGW1BSnGmBV7K9fSjff Gk2YcEGt5RJcq/I4I20sdnGpEi6ch01XgV+/bla7F4LJaFA6SZIPHWBPgxk9pDm2yknm aEtw== X-Gm-Message-State: APjAAAVF+VRzxAk7Pegf20+Wa9bYib2x3ZnpG6h5U+PNChEuA9Ea9fNA YYikyxPKcJqI4zQ2EdqtnHep1E5DVBR0RjBS0dNbj5Qc X-Google-Smtp-Source: APXvYqyOXpczCvSb/08wmz53nVamaX5CCRTWAwxrHMGW/rvFFx6GFTGafocHgQoREJn+DfNsviafnWBzpUNQplb5Xlg= X-Received: by 2002:aca:4c88:: with SMTP id z130mr6245457oia.170.1552791338956; Sat, 16 Mar 2019 19:55:38 -0700 (PDT) MIME-Version: 1.0 From: Sebastian Gniazdowski Date: Sun, 17 Mar 2019 03:55:27 +0100 Message-ID: Subject: Problem with a substitution To: Zsh Users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello, I think that the parsing of command line can be performed by 1-2 substitutions. Below is the one that I'm currently working on: ${(j::)${@[@]//(#b)(--quiet|-q|--force|-f)[[:blank:]=3D]#(([a-zA-Z-]#)~(--q= uiet|-q|--force|-f))#/${TARGET[${match[1]}]::=3D${match[1]}//${${match[2]:+= ${match[2]}}:-1} }}} Explanation: ${(j::)${@[@]// # Work on the command line arguments =E2=80=93 substitute sub-strings (i.e. the "//" substitution) (#b)(--quiet|-q|--force|-f) # Enable $match array (the #b); match 4 different option cases [[:blank:]=3D]# # Optional before-option's-value space and =3D (([a-zA-Z-]#)~(--quiet|-q|--force|-f))# # Optional value =E2=80=93 a string from letters and dashes, but not any of the 4 option-names / # Substitute to: ${TARGET[${match[1]}]::=3D${match[1]} # option name, also assigning it to the TARGET hash (the ::=3D) //${${match[2]:+${match[2]}}:-1} }}} # After-//, also assign optional option's value (using "1" if there's no va= lue) So, for the following input: set -- --quiet -fa -q local -A TARGET the output of: print -r -- ${(j::)${@[@]//(#b)(--quiet|-q|--force|-f)[[:blank:]=3D]#(([a-z= A-Z-]#)~(-q|--force|-f))#/${TARGET[${match[1]}]::=3D${match[1]}//${${match[= 2]:+${match[2]}}:-1} }}} is: --quiet//1 -f//1 -q//1 and for: print -rl -- ${(kv)TARGET} it is (keys and values alternating): -q -q//1 --quiet --quiet//1 -f -f//1 I.e.: there's no "-f//a" string in it. Why? -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org