From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10607 invoked by alias); 4 Dec 2015 00:59:51 -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: X-Seq: 21041 Received: (qmail 29811 invoked from network); 4 Dec 2015 00:59:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version:content-type; bh=VWFcebqhLc2wd+Tq2BJCQxS4Z7dqG0vUgjP9j1FvAtc=; b=DKo8YZ4oJhZJTAk2U2auArSxAm7urbSFPgr86JcABeKU6KiKiEDScwefqCRLCH3xj2 Of68UyrFIcrepqk8RmzI2JNAkuuPnNOdN+7AVttQvfoo/TK26rbyzJRFl+YkAxaiuPvV H9PR6B046k1WGmrL3XM52Gcxpu5kC0unI0sXiw2PiCSDVT4OVVfj7qh4BsTWZJhqXCZc GuI1OUadcY72eiMYMfT+4NzWFTXf0g/q3wmLin7TZtnFZkJnkETLFLqFoO5kjji2JAPz z5y0at8Lq32b7pgnoNSJptpv/el4yhBxPrXcmZoCpnxCtJmDewppHj6x/QUDxbMZZc+Z pCrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=VWFcebqhLc2wd+Tq2BJCQxS4Z7dqG0vUgjP9j1FvAtc=; b=cUpPTAUOu1qnGm5NvUABvqcCGhfL0m1RlRVx5jl+O5Sp6bsZlS/mVe14b0HX3V3SPz RRKWkuino/wznw6McFAhxvsG2GH5YmGH8NmjRaUNMJ/QrS9T93ZGmjxZerhh69YBzAJa flMJwSDGvxPGmhm+amvqtcwVQkzGoTsAjdE3w6129VwChdEEF/u25zaBN8cbynPBstxa +DRouX+H3Y5x6CsVgRYghWWX3j99MgvJ2cSP9qEA3tDVys67gcaQB1YaIc+8sFIVUAtg nmn7Z76NuwCyFohant6LthlXo+bKj7ygxQGM+qoct0/93Cv36rmYF9ELCw/Zvko2/1R3 CVfA== X-Gm-Message-State: ALoCoQnPpkJ17A6Mn5Hpqs4RJIpOMWMRz/FYJMWjYIMhDdqKLNGUXhlg5Qzo5rZPRtSBKjsTjCnC X-Received: by 10.98.17.131 with SMTP id 3mr17449363pfr.57.1449190788878; Thu, 03 Dec 2015 16:59:48 -0800 (PST) From: Bart Schaefer Message-Id: <151203165950.ZM13362@torch.brasslantern.com> Date: Thu, 3 Dec 2015 16:59:50 -0800 In-Reply-To: <20151203233926.GF1955@tarsus.local2> Comments: In reply to Daniel Shahaf "Re: Interactive search on the command line?" (Dec 3, 11:39pm) References: <20151126080400.GA20074@linux.vnet.ibm.com> <565B723B.70900@gmail.com> <20151130031915.GD2504@tarsus.local2> <20151203233926.GF1955@tarsus.local2> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: Interactive search on the command line? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Dec 3, 11:39pm, Daniel Shahaf wrote: } } So, you could do something like this (using the (b::) subscript flag as } well): } } % () { } local haystack="$1" } local needle="a" } integer idx } while (( idx = ${haystack[(ib:idx+1:)${needle}]} )) } (( idx <= $#haystack )) } do } print -r - $haystack[idx,idx+$#needle-1] } done } } foobar } a } % This example might be a little clearer if we show the index where the match was found and use a match pattern longer than one character: % () { local haystack=$1 needle=$2 integer idx while idx=${haystack[(ib:idx+1:)$needle]} (( idx <= $#haystack )) do print -r - $idx $haystack[idx,idx+$#needle-1] done } foobar 'o??' 2 oob 3 oba % (I also removed all redundant quotes and braces, since the original would only work in native zsh emulation anyway.)