From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3255 invoked by alias); 6 May 2016 00:37:26 -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: X-Seq: 38407 Received: (qmail 5568 invoked from network); 6 May 2016 00:37:22 -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 autolearn=ham autolearn_force=no version=3.4.1 X-Injected-Via-Gmane: http://gmane.org/ To: zsh-workers@zsh.org From: Thilo Six Subject: [PATCH] allopt() and question Date: Fri, 6 May 2016 02:17:32 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------020508040002040701010003" X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: p57a552c2.dip0.t-ipconnect.de X-Mozilla-News-Host: news://news.gmane.org:119 --------------020508040002040701010003 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hello 1) i looked at allopt() and while doing that i noticed that it would not give correct results for some options. notable e.g. monitor and zle. Here i get: % builtin set -o . . monitor on . . zle on but then: % builtin set -o | command grep -E '(\|\)' monitor off zle off >>From that I guess that Zsh resets some specific options when used in pipes/command substitutions. The attached allopt() works around that. Additionally: This version makes it possible to throw s.th. like '_H-uP' or 'NO__H-uP' at allopt and does not hardcode length of options when printing. KUDOS for that goes to pws: http://zsh.sourceforge.net/Guide/zshguide05.html 2) While working on the above i noticed that 'builtin set -o' and '${options}' are not equal. The later knows some more. See attached missing_options for a list. This makes me wonder if that is intended. Any comments are welcome. kind regards, Thilo --------------020508040002040701010003 Content-Type: text/x-diff; name="0001-allopt-updated.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-allopt-updated.patch" >>From 24207db8f420e65ba4e98875ee97c398135bb9b2 Mon Sep 17 00:00:00 2001 From: Thilo Six Date: Fri, 6 May 2016 01:34:29 +0200 Subject: [PATCH] allopt() * FIX: some options are reset inside pipes and command substition e.g. monitor and zle those were displayed with wrong state * FIX: do not hardcode length for print out thanks to pws: http://zsh.sourceforge.net/Guide/zshguide05.html * MOD: make it possible to throw s.th. like '_H-uP' at allopt --- Functions/Misc/allopt | 56 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/Functions/Misc/allopt b/Functions/Misc/allopt index 0c521f3..3955b88 100644 --- a/Functions/Misc/allopt +++ b/Functions/Misc/allopt @@ -6,20 +6,46 @@ # via egrep. # # Written by Sweth Chandramouli with hacks by Bart Schaefer. +# updated by Thilo Six -listalloptions () { - local OPT_NAME OPT_VALUE - builtin set -o | while read OPT_NAME OPT_VALUE ; do - if [[ ${OPT_NAME#no} != ${OPT_NAME} ]] ; then - OPT_VALUE=${(L)${${OPT_VALUE:s/on/OFF}:s/off/on}} - OPT_NAME=${OPT_NAME#no} - fi - echo "${(r:21:)OPT_NAME} ${OPT_VALUE}" - done -} +# allopt() { + local OPT_NAME OPT_VALUE LENGTH i OUT + local -a OPT_NAMES_ALL + local -A OPT_ALL + OPT_NAMES_ALL=(${(o)${(k)options[@]}}) + + # http://zsh.sourceforge.net/Guide/zshguide05.html + LENGTH=$(( ${#${OPT_NAMES_ALL[(r)${(l.${#${(O@)OPT_NAMES_ALL//?/X}[1]}..?.)}]}} + 1 )) + + ### XXX note: + # this needs to be done because otherwise + # the listing is inaccurat e.g. 'monitor' and 'zle' are always off + # the set builtin treats them special within a pipe. compare this: + # % builtin set -o + # with + # % builtin set -o | command grep -E '(\|\)' + # + for i in ${OPT_NAMES_ALL} ; do + OPT_ALL+=($i ${options[$i]}) + done + + if [[ -n ${*} ]]; then + { + for i in ${OPT_NAMES_ALL} ; do echo "${i} ${OPT_ALL[$i]}" ; done | while read OPT_NAME OPT_VALUE ; do + if [[ ${OPT_NAME#no} != ${OPT_NAME} ]] ; then + OPT_VALUE=${(L)${${OPT_VALUE:s/on/OFF}:s/off/on}} + OPT_NAME=${OPT_NAME#no} + fi + echo "${(r:${LENGTH}:)OPT_NAME} ${OPT_VALUE}" + done } | egrep ${(j.|.)${${${(L)@}#no}//[-_]/}} + else + for i in ${OPT_NAMES_ALL} ; do echo "${i} ${OPT_ALL[$i]}" ; done | while read OPT_NAME OPT_VALUE ; do + if [[ ${OPT_NAME#no} != ${OPT_NAME} ]] ; then + OPT_VALUE=${(L)${${OPT_VALUE:s/on/OFF}:s/off/on}} + OPT_NAME=${OPT_NAME#no} + fi + echo "${(r:${LENGTH}:)OPT_NAME} ${OPT_VALUE}" + done + fi +# } -if [[ -n $@ ]]; then - listalloptions | egrep "${(j.|.)@}" -else - listalloptions -fi -- 2.8.1 --------------020508040002040701010003 Content-Type: text/plain; charset=UTF-8; name="missing_options" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="missing_options" LS0tIHNldAkyMDE2LTA1LTA1IDIyOjQxOjAxLjIwMjA5MjEzNCArMDAwMAorKysgYWxsb3B0 CTIwMTYtMDUtMDUgMjI6NDA6MDYuNTg1MDkzODY5ICswMDAwCkBAIC0yMSw4ICsyMSw5IEBA CiBiYXNocmVtYXRjaAogYmVlcAogYmduaWNlCiBicmFjZWNjbAorYnJhY2VleHBhbmQKIGJz ZGVjaG8KIGNhc2VnbG9iCiBjYXNlbWF0Y2gKIGNiYXNlcwpAQCAtNDMsOCArNDQsOSBAQAog Y3NoanVua2llcXVvdGVzCiBjc2hudWxsY21kCiBjc2hudWxsZ2xvYgogZGVidWdiZWZvcmVj bWQKK2RvdGdsb2IKIGR2b3JhawogZW1hY3MKIGVxdWFscwogZXJyZXhpdApAQCAtNjMsMTQg KzY1LDE3IEBACiBnbG9iY29tcGxldGUKIGdsb2Jkb3RzCiBnbG9ic3RhcnNob3J0CiBnbG9i c3Vic3QKK2hhc2hhbGwKIGhhc2hjbWRzCiBoYXNoZGlycwogaGFzaGV4ZWN1dGFibGVzb25s eQogaGFzaGxpc3R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