179 days ago · Tech · hide · Fediverse post

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…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town