1 hour ago · Tech · 0 comments

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 # Edit file in stream by writing to a file, opening the editor and printing back to stdout # # File will be stored in a temp file in the current directory and deleted once edit is complete # # Example edit # > bat package.json | f edit-stream json | save updated.json # def "f edit-stream" [ # extension to use when writing the file. Useful to get syntax highlighting ext: string = "txt", # prefix to be used for tempfile prefix: string = "ed-", # if the temp file should be retained after editing --keep, ] { let f = $"($prefix)(date now | format date '%+').($ext)" $in | save $f nu -c $"($env.EDITOR) ($f)" if !$keep { bat $f } } This is a Nushell function which makes it possible…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.