Sort-ISE (modification of post by view diff)
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/792"></script>download | new post
This function sorts the open editor pane starting at a specific column using the next length characters. It would be nice to wrap it with a small function showing a dialog to querry this values and to put this into the custom menue.
- function Sort-ISE ()
- {
- <#
- .SYNOPSIS
- ISE Extension sort text starting at column $start comparing the next $length characters
- .DESCRIPTION
- ISE Extension sort text starting at column $start comparing the next $length characters
- Leftmost column is column 1
- .NOTES
- File Name : Sort_ISE.ps1
- Author : Bernd Kriszio - http://pauerschell.blogspot.com/
- Requires : PowerShell V2 CTP3
- .LINK
- Script posted to:
- .EXAMPLE
- Sort-ISE 1 10
- #>
- #requires -version 2.0
- param (
- [Parameter(Position = 0, Mandatory=$false)]
- [int]$start = 1,
- [Parameter(Position = 1, Mandatory=$false)]
- [int]$length = -1
- )
- $newlines = @{}
- $editor = $psISE.CurrentOpenedFile.Editor
- $caretLine = $editor.CaretLine
- $caretColumn = $editor.CaretColumn
- $text = $editor.Text.Split("`n")
- foreach ($line in $text){
- $key = [string]::join("", $line[($start - 1)..($start - 1 + $length)])
- if ( $newlines[$key] -ne $null) {
- $newlines[$key] = $newlines[$key] + $line
- }
- else {
- $newlines[$key] = $line
- }
- }
- $Sortedkeys = $newlines.keys | sort
- $newtext = ''
- foreach ($key in $Sortedkeys){
- $newtext += $newlines[$key]
- }
- $editor.Text = $newtext
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository