Skip to content

Commit

Permalink
Added quoting of path if has spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
guyrleech authored Aug 20, 2024
1 parent cfdfa62 commit 53a6f92
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions totsclient.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Function totsclient( [string]$path , [switch]$noClipboard , [string]$prefix = 't
else
{
## deal with absolute path which may or may not be quoted at start with "
[string]$tsclientPath = $path -replace '^(?<quote>"?)(?<drive>\w):' , "`${quote}\\$prefix\`${drive}$suffix"
[string]$tsclientPath = $path.Trim() -replace '^(?<quote>"?)(?<drive>\w):' , "`${quote}\\$prefix\`${drive}$suffix"
if( $tsclientPath -ieq $path )
{
Write-Warning -Message "No change made to path $path"
Expand All @@ -47,7 +47,15 @@ Function totsclient( [string]$path , [switch]$noClipboard , [string]$prefix = 't
}
else
{
"`"$tsclientPath`"" | Set-Clipboard
## quote it if contains spaces and not already quoted
if( $tsclientPath -match '^[^"].*\s+' )
{
"`"$tsclientPath`"" | Set-Clipboard
}
else ## no need for quoting
{
$tsclientPath | Set-Clipboard
}
}
}
}
}

0 comments on commit 53a6f92

Please sign in to comment.