>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