Commits

Kevin Berridge committed 806d891

sqlps: adds custom tab expansion fixing performance problems with sqlps

  • Participants
  • Parent commits 0c810f5

Comments (0)

Files changed (1)

File Microsoft.SqlServer.Management.PowerShell.sqlps_profile.ps1

   $sql
   invoke-sqlcmd $sql
 }
+
+if ((test-path function:\TabExpansion) -and !(test-path function:\TabExpansionSqlPsBackup)) {
+  rename-item function:\TabExpansion TabExpansionSqlPsBackup
+}
+
+function TabExpansion($line, $lastWord) {
+  if (!((get-location).Provider.Name -eq "SqlServer")) {
+    TabExpansionSqlPsBackup $line $lastWord
+  }
+  else {
+    $aindex = $lastWord.LastIndexOf('\')
+    $bindex = $lastWord.LastIndexOf('/')
+    $index = (($aindex, $bindex) | measure-object -max).Maximum
+    if ($index -gt -1) { 
+      $parent = $lastWord.substring(0, $index+1) 
+      $leaf = $lastWord.substring($index+1)
+    }
+    else {
+      $parent = ""
+      $leaf = $lastWord
+    }
+
+    $matches = ls -path $parent | ?{ $_.PSChildName -match "^$leaf" }
+    if ($matches) { 
+      $matches | %{ $parent + $_.PSChildName } 
+    } 
+    else {$lastWord}
+  }
+}