nearly pointless powershell – 2016-09-30-rld

howdy y’all,

had a few moments of boredom jump up and attack me. in self defense, i decided to do a smidgen of powershell. here it is [yes, it’s ugly. that’s most of the point!] …


grabs the current clipboard contents,

checks for the mornonic ‘four spaces’ leading & trailing lines & creates them if needed

checks for the still moronic ‘four spaces’ leading characters on the other lines & adds them if needed

puts the new version on the clipboard

$ClipOut = @()
$FourSpaces = ‘ ‘ * 4

single item array with four spaces and a line-end/new-line

seems needed to add to the BEGINNING of the $ClipIn array

$RedditCodeMarker = @(,”$FourSpaces`n”)

$ClipIn = Get-Clipboard

if ($ClipIn[0] -ne $RedditCodeMarker)
{
$ClipIn = $RedditCodeMarker + $ClipIn
}
if ($ClipIn[-1] -ne $RedditCodeMarker)
{
$ClipIn += $RedditCodeMarker
}

foreach ($Line in $ClipIn)
{
if (-not $Line.StartsWith($FourSpaces))
{
$Line = $FourSpaces + $Line
}
$ClipOut += $Line
}

Set-Clipboard $ClipOut


the above is without the code formatting, obviously. [grin] below is the result …


grabs the current clipboard contents, checks for the mornonic 'four spaces' leading & trailing lines & creates them if needed checks for the still moronic 'four spaces' leading characters on the other lines & adds them if needed puts the new version on the clipboard $ClipOut = @() $FourSpaces = ' ' * 4 single item array with four spaces and a line-end/new-line seems needed to add to the BEGINNING of the $ClipIn array $RedditCodeMarker = @(,"$FourSpaces`n") $ClipIn = Get-Clipboard if ($ClipIn[0] -ne $RedditCodeMarker) { $ClipIn = $RedditCodeMarker + $ClipIn } if ($ClipIn[-1] -ne $RedditCodeMarker) { $ClipIn += $RedditCodeMarker } foreach ($Line in $ClipIn) { if (-not $Line.StartsWith($FourSpaces)) { $Line = $FourSpaces + $Line } $ClipOut += $Line } Set-Clipboard $ClipOut 

seems to work fine. any comments on the logic? i already know you all have hissy fits over my indentation style, so i left that out. [grin]

i suppose one could set up an icon with a shortcut key [perhaps ctrl-shft-k] to run the code on demand. i aint sure it’s worth it, tho.

take care,
lee

submitted by /u/Lee_Dailey
[link] [comments]

Leave a Reply