Email Quoting and Wrapping in 59 Bytes

Here’s a useful bit of line noise that I came up with when I wanted to put some quoted text into email.  Starting with unwrapped text in the clipboard:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

It generates:

[D:\Temp]
PS:30 > pclip | %{[Regex]::Split($_,’(.{0,60}(?:\s|$))’)}|%{if($_){“> $_”}}
> Lorem ipsum dolor sit amet, consectetur adipisicing elit,
> sed do eiusmod tempor incididunt ut labore et dolore magna
> aliqua. Ut enim ad minim veniam, quis nostrud exercitation
> ullamco laboris nisi ut aliquip ex ea commodo consequat.
> Duis aute irure dolor in reprehenderit in voluptate velit
> esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
> occaecat cupidatat non proident, sunt in culpa qui officia
> deserunt mollit anim id est laborum.

(pclip is the clipboard paste utility available from http://unxutils.sourceforge.net/)

Edit: Here’s a version that’s 16 characters shorter using V2′s -split operator!

(pclip)-split’(.{0,60}(?:\s|$))’|?{$_}|%{“> $_”}

Have any densely useful snippets you’d like to share?

2 Responses to “Email Quoting and Wrapping in 59 Bytes”

  1. Keith Hill writes:

    FYI the PowerShell Community Extensions snapin has a Get-Clipboard cmdlet also: http://www.codeplex.com/Wiki/View.aspx?ProjectName=PowerShellCX

  2. Sung Kim writes:

    I have a feeling that the above oneliner can win a obfustication contest for PowerShell had there been one ;)

Leave a Reply