Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[RFC] zsh/getopx — zsh interface to getopt_long(3)
- X-seq: zsh-workers 42076
- From: dana <dana@xxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [RFC] zsh/getopx — zsh interface to getopt_long(3)
- Date: Mon, 4 Dec 2017 21:24:32 -0600
- 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==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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 — 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=${1#-}; shift ;;
-h|--help) : print help; return 0 ;;
-n|--lines) : validate $2 somehow; lines=$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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author