Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Substituting grep (and other) output to open files in Vim
- X-seq: zsh-users 16013
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Richard Hartmann <richih.mailinglist@xxxxxxxxx>
- Subject: Re: Substituting grep (and other) output to open files in Vim
- Date: Tue, 10 May 2011 16:12:37 +0200
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=zVj5tFPWmtXVa3H4YyfB2ZlmabVJSbV7bf1vjKAyB6E=; b=n3fEdOpYoYV8AOM8/nrqoTQVm19Q8unDykEtoWjmp1x/Kkb5qABSZB610besBYaZIT 8xl7UPAD5GnNOCBp8UPWsrvKDvmRb2RIrzXBTUVOwswOtGba5pQ860Agsx/wVfyXgJSY tVI2MCURaStM4lugVAIz3SP0ZsqChylp08CcY=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=JTfy17onjdFjXszeyI1IBI2al9YTrNLTClRnIHEtsOFZAgp7blE9aS/mHG8xjABObS FBtAcpLvSmY/fWDfVokideEZ8jCbZDVlq9RSeM6dW4r3vpWJoui8LZDr6lJ87BC9Fgxd k61MpDWUMwPKFrSJkiL5LCBCjpG1J4AHUdxfY=
- In-reply-to: <BANLkTik+65NedRoVNJMgj9+Oma_XDmz8dA@mail.gmail.com>
- 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: <BANLkTik+65NedRoVNJMgj9+Oma_XDmz8dA@mail.gmail.com>
On 10 May 2011 15:46, Richard Hartmann <richih.mailinglist@xxxxxxxxx> wrote:
> Hi all,
>
> I would like to be able to do the following, but I am stuck. Every
> pair of lines is what I would execute and what it would be transferred
> to. I am assuming that every file "name" (i.e. including colons etc) I
> am running Vim on does not exist. If it exists, it should be opened
> instead of magic happening. "foo" exists while "foo:" etc do not.
>
> vim foo:
> vim foo
>
> vim foo:bar
> vim foo
>
> vim foo:123
> vim foo +123
>
> vim foo:123:
> vim foo +123
>
> vim foo:123:bar
> vim foo +123
>
> Ideally, the same would happen for vimdiff. And yes, vimdiff heeds
> only one +n and the last one on the command line wins. That's fine.
>
>
> I am pretty sure this is trivial to do in zsh, but as I said I am at a
> loss as to how..
>
>
> Thanks,
> Richard
>
This only does the foo:123: case, but you should be able to adapt it,
if [[ $1 =~ ^(.*[^/]):([0-9]+):$ ]]; then
1=$match[1]
2=+$match[2]
fi
I also have a non-regex version commented out, it is arguably less readable,
if [[ $1 = *[^/]##:(#b)([0-9]##)(#B): ]]; then
2=+${1[$mbegin[1],$mend[1]]}
1=${1[1,$mbegin[1]-2]}
fi
Ahead of this you'll want to check test -f $1 to avoid munging the
argument if the file exists.
Changing the regex to ^(.*[^/]):([0-9]+)[^0-9].*$ should cover two of
your other cases, but you might want to be more restrictive than .*
there, not sure what you want to allow bar to be.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author