From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7555 invoked by alias); 5 Dec 2017 03:24:41 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42076 Received: (qmail 29889 invoked by uid 1010); 5 Dec 2017 03:24:41 -0000 X-Qmail-Scanner-Diagnostics: from mail-it0-f47.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.214.47):SA:0(-1.9/5.0):. Processed in 2.980296 secs); 05 Dec 2017 03:24:41 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=nn9xKIRQ0cpk3n++R/1ZajpRBQf7LgeknEq1SAFIyu8=; b=b7DXOjcK73viq9dRbHskUAhKwzfW01YjgGmmIE7p9iUYii4K8Rg/901aFsBXkvJKBv U8tuuCEL7lThBtCgYLRTMfdyXTJEGrmpRxY40dwV76f4EVMe5/EHN5BwZz4wlTwt8B0C tLEWQoEOVOex4PKYoEPBRdjI4zM4Uzx1l0o6JyUbuxfcAV9oWGdPYnverrkiWHp9v/5s sBPaEvftsFcc26pAJZIzmbTxclTNNnlGEf/FneTwXMVK1zTnM1Hbjge2Jdb0uUqqrzYn rOZjCViwH5GwIqt/80BcvrtTBQZ9lU7JiUZSBba+G+SVQnktysqlj+7fiQ29DgqCzMNi CTUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=nn9xKIRQ0cpk3n++R/1ZajpRBQf7LgeknEq1SAFIyu8=; b=EQV5Uk/qBnpBQgt/f4TluzjAJEpc7qGGFQco+MSk4BtggH1lkmpA4yWzuZQdUQn/oB lEac0PbtRpLcik4u6FutP1ZqNsbXK9KoC6pRX1kYZxUjyx5XkbnQDxU/M6WMkTRz9/DZ uCWnRzy9wzjxBrKEaWhogV8LMCArTEtQNafcN3xc78aA6DeKvnmX3YsHmcjLOoBHBDOW oHnn9E96/SXTP1whewcV2verW+gMnpMy9BVrkSY97f7DZazqshGMHkSnqOyWV/Agzkvt 0TuMngkCxpd9gz9IpW+wfcrathsj77LGOEwR9W76uhbutkB5C4my+QtMiXUV27cyK1iI JJ+g== X-Gm-Message-State: AJaThX72+AvsoOegpYT+SGstZ3YIyEQq3G8A7IA67BnmvVgZRWyZDODs 38XKYZl0yASwK31L56OSnP3BS7cmbiw= X-Google-Smtp-Source: AGs4zMY+kcqjH67fCjbC3ZHnUSu+M6bCFba9FF1jEwQ52s2XGMQ/qKGohU9TRP3YkRvAEQs/8ub7vQ== X-Received: by 10.107.20.1 with SMTP id 1mr25576425iou.170.1512444274497; Mon, 04 Dec 2017 19:24:34 -0800 (PST) From: dana Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: =?utf-8?Q?=5BRFC=5D_zsh/getopx_=E2=80=94_zsh_interface_to_getopt?= =?utf-8?Q?=5Flong=283=29?= Message-Id: <2E5167F1-0116-474F-9039-9CD8E5BF6E9F@dana.is> Date: Mon, 4 Dec 2017 21:24:32 -0600 To: zsh-workers@zsh.org X-Mailer: Apple Mail (2.3273) Hey there, In my 'consumer' shell scripts i often use the util-linux version of = getopt(1), which provides many functionality and ease-of-use benefits compared to = the BSD getopt(1), the getopts built-in, and the zparseopts built-in, by way of getopt_long(3). The major down side to this utility is that it's rather = hard to come by on non-GNU/Linux systems. Since getopt_long(3) itself has been portable across all of the major = UNIX-like systems for about 15 years now, it seemed like subsuming that = functionality into zsh via a module might be a decent idea. So i've done that, or at least = i've got a working prototype: https://github.com/okdana/zsh/blob/dana/getoptx/Src/Modules/getoptx.c I'm not a fantastic C programmer so there's probably a lot of weird = stuff like questionable allocations and temp variables, the code doesn't conform to = the zsh style guide lines, and i'm not super married to either the name or the = API =E2=80=94 but other than that it seems to do the job. Here's a partial usage example illustrating the current API (including the -c option, which makes it = easier to support use cases like `tail -15` by leaving adjacent numeric options = grouped together): getoptx -cEA argv -l help,lines:,version hn:V || return 1 while (( $# )); do case $1 in -[0-9]##) lines=3D${1#-}; shift ;; -h|--help) : print help; return 0 ;; -n|--lines) : validate $2 somehow; lines=3D$2; shift 2 ;; -V|--version) : print version; return 0 ;; --) shift; break ;; # any remaining argv are operands esac done Do you reckon this is something that might be suitable for inclusion = into the main project (assuming i get it cleaned up)? Or is the arg-parsing = 'market' too saturated already with the alternatives i mentioned? (Of course, any other thoughts you might have would be appreciated too.) cheers dana