From 620dc15a42dd5e228649ae2cb0fc7b8cea254e74 Mon Sep 17 00:00:00 2001 From: Cydroz <46122593+Cydroz@users.noreply.github.com> Date: Mon, 6 Jan 2025 23:36:30 +1100 Subject: [PATCH 1/3] Define and use $total variable --- snippets/PowerShell.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index e5b23be643..9371047850 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -165,8 +165,9 @@ "prefix": "foreach-progress", "description": "Insert a foreach loop with Write-Progress initialized", "body": [ - "\\$progPercent = \"{0:n2}\" -f ([math]::round(\\$i/\\$array.count,4) * 100)", - "Write-Progress -Activity \"${3:activityName}\" -Status \"\\$i of \\$array.count - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", + "\\$total = \\$${1:array}.count", + "\\$progPercent = \"{0:n2}\" -f ([math]::round(\\$i/\\$total,4) * 100)", + "Write-Progress -Activity \"${3:activityName}\" -Status \"\\$i of \\$total - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", "\\$i = 1", "foreach ($${2:item} in $${1:array}) {", " \\$progPercent = \"{0:n2}\" -f ([math]::round(\\$i/\\$total,4) * 100)", @@ -670,4 +671,4 @@ "}" ] } -} +} \ No newline at end of file From 507c021d7acf82bf2d3db307c2cb5d6e4f770707 Mon Sep 17 00:00:00 2001 From: Cydroz <46122593+Cydroz@users.noreply.github.com> Date: Mon, 6 Jan 2025 23:36:55 +1100 Subject: [PATCH 2/3] Define $i before use --- snippets/PowerShell.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 9371047850..5ae01e3082 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -166,9 +166,9 @@ "description": "Insert a foreach loop with Write-Progress initialized", "body": [ "\\$total = \\$${1:array}.count", + "\\$i = 1", "\\$progPercent = \"{0:n2}\" -f ([math]::round(\\$i/\\$total,4) * 100)", "Write-Progress -Activity \"${3:activityName}\" -Status \"\\$i of \\$total - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", - "\\$i = 1", "foreach ($${2:item} in $${1:array}) {", " \\$progPercent = \"{0:n2}\" -f ([math]::round(\\$i/\\$total,4) * 100)", " Write-Progress -Activity \"${3:activityName}\" -Status \"\\$i of \\$total - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", From 34f40ba0038334741e99fe64b7a7c487f552ef7d Mon Sep 17 00:00:00 2001 From: Cydroz <46122593+Cydroz@users.noreply.github.com> Date: Mon, 6 Jan 2025 23:48:04 +1100 Subject: [PATCH 3/3] Add tab step to customise increment varname --- snippets/PowerShell.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 5ae01e3082..d0a94ba30b 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -166,16 +166,16 @@ "description": "Insert a foreach loop with Write-Progress initialized", "body": [ "\\$total = \\$${1:array}.count", - "\\$i = 1", - "\\$progPercent = \"{0:n2}\" -f ([math]::round(\\$i/\\$total,4) * 100)", - "Write-Progress -Activity \"${3:activityName}\" -Status \"\\$i of \\$total - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", + "\\$${4:i} = 1", + "\\$progPercent = \"{0:n2}\" -f ([math]::round(\\$${4:i}/\\$total,4) * 100)", + "Write-Progress -Activity \"${3:activityName}\" -Status \"\\$${4:i} of \\$total - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", "foreach ($${2:item} in $${1:array}) {", - " \\$progPercent = \"{0:n2}\" -f ([math]::round(\\$i/\\$total,4) * 100)", - " Write-Progress -Activity \"${3:activityName}\" -Status \"\\$i of \\$total - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", + " \\$progPercent = \"{0:n2}\" -f ([math]::round(\\$${4:i}/\\$total,4) * 100)", + " Write-Progress -Activity \"${3:activityName}\" -Status \"\\$${4:i} of \\$total - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", " # Insert Code Here", " ${0}", " ", - " \\$i++", + " \\$${4:i}++", "}", "" ]