Last active
July 9, 2021 09:51
-
-
Save PrateekKumarSingh/df9b0b0697c1b9a1e2416afa7d22f7b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-Comment | |
{ | |
Param([Parameter(Position=0)] [String] $FilePath,[Switch] $FromClipBoard) | |
If($FilePath) | |
{ | |
$Content = Get-Content $FilePath | |
} | |
elseif($FromClipBoard) | |
{ | |
$Content = [Windows.clipboard]::GetText() | |
} | |
else | |
{ | |
Write-Host "Please provide a file/content to look for comments." | |
} | |
$CommentTokens = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$null) | ` | |
Where-Object{$_.type -like "*comment*"} | |
Foreach($obj in $CommentTokens) | |
{ | |
$IndentSpace = "" | |
If($obj.StartColumn -gt 1) | |
{ | |
1..($obj.startcolumn - 1)| %{[String]$IndentSpace += " "} | |
#$IndentSpace+$obj.content | |
} | |
''| select @{n='Line';e={$obj.StartLine}}, @{n="Comment";e={$IndentSpace+$obj.Content}} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment