Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Interactive search on the command line?
- X-seq: zsh-users 21041
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Interactive search on the command line?
- Date: Thu, 3 Dec 2015 16:59:50 -0800
- 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==
- In-reply-to: <20151203233926.GF1955@tarsus.local2>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20151126080400.GA20074@linux.vnet.ibm.com> <565B723B.70900@gmail.com> <20151130031915.GD2504@tarsus.local2> <CAGjUN-TEPKNr3fKfUvL1JBtZN9y2jrw9m1kjstggEeR+12gjcA@mail.gmail.com> <20151203233926.GF1955@tarsus.local2>
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.)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author