Editing Text in-stream
02 June 2026
Updated: 02 June 2026
I’ve recently been finding sed really handy but sometimes I want to edit something bigger in-stream - maybe just to make some small manual fixes before dumping dumping a string out to some other command. I’ve been using pbcopy a lot for this kind of thing but I wanted a neater way to do it, and here’s my solution
1# Edit file in stream by writing to a file, opening the editor and printing back to stdout2#3# File will be stored in a temp file in the current directory and deleted once edit is complete4#5# Example edit6# > bat package.json | f edit-stream json | save updated.json7#8def "f edit-stream" [9 # extension to use when writing the file. Useful to get syntax highlighting10 ext: string = "txt",11 # prefix to be used for tempfile12 prefix: string = "ed-",13 # if the temp file should be retained after editing14 --keep,15 ] {16 let f = $"($prefix)(date now | format date '%+').($ext)"17
18 $in | save $f19 nu -c $"($env.EDITOR) ($f)"20
21 if not $keep {22 bat $f23 }24}25
26alias fed = f edit-streamThis is a Nushell function which makes it possible to do just that, and in practice could look something like this:
1bat package.json # open a file using `bat`2| f edit-stream json # open the file in the configured $EDITOR3| save updated.json # save this to some other outputBy default this also uses bat to print the output to give syntax highlighting to users but will also pass the plain text on if being passed to another command