Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Open editor to create/edit stdin before feeding to a command
- X-seq: zsh-users 13513
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh users mailing list <zsh-users@xxxxxxxxxx>
- Subject: Re: Open editor to create/edit stdin before feeding to a command
- Date: Mon, 01 Dec 2008 21:20:31 -0800
- In-reply-to: <20081201215146.GA11552@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20081201215146.GA11552@xxxxxxxxxxxxxxxxxxxxxxxxxx>
On Dec 1, 10:51pm, martin f krafft wrote:
}
} I recently discovered edit-command-line[0] and that made me think
} that zsh should really get a feature which would allow the user to
} use an editor to feed data to a command's stdin, basically
} a simplified here-document, e.g. with a syntax mockup:
}
} # opens editor on tmpfile, feeds file to wc stdin on close
} ~$ wc <<!
Unfortunately there's very little syntax you can use following "<<"
that would not potentially be in conflict with an existing here-
document. In particular I've seen a number of scripts that use
something <<!
misc. text
!
(and so on with other punctuation).
However, you can get Awfully Darn Close (TM) to this already with a
couple of simple tricks.
For example:
function edcat {
emulate -L zsh
if (( $# )); then
${VISUAL:-${EDITOR:-vi}} $* </dev/tty >&/dev/tty && cat $*
else
edcat =(:)
fi
}
alias -g '@!'='<<(edcat)'
And then:
$ wc @!
} # puts cat output into tmpfile, opens editor, feeds tmpfile to wc
} # on close
} ~$ cat |! wc
This one is trickier, requiring an explicit subshell to force the editor
to run synchronously. However, it can use the same "edcat" function.
alias -g @@='|( exec 3<&0 && edcat =(cat <&3) )|'
$ print lookee here @@ wc
A lot of interesting things can be done with global aliases and sequences
of characters that are unlikely to need to appear unquoted otherwise.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author