Familiar with the following?

You are aware of (shell)file which contains a interesting line and you think: "I want to execute this line on the command prompt". Most people will do the following:

% more <file>
[select interesting bit with your mouse]
[paste]<enter>

And the code gets executed.

I propose the following function: f(), which does the following:

  1. It opens the file in $EDITOR (:= vim of course);
  2. You delete everything you don't want to execute;
  3. What's left gets executed;
  4. And it is added to your shell's history.

The code of the function looks like this:

1 int main(int c) {
2     printf("This is nice");
3     exit(1);
4 }

It should either be possible to use this verbatim in bash or make it work with a few tweaks.

Tags: zsh

0 comments

Comments are closed

If you really, really want to comment, please mail miek@miek.nl.

0 comments in moderator queue