简体   繁体   English

在Powershell标签自动完成中更改过滤器方法

[英]Change filter approach in powershell tab auto complete

Currently in Powershell when I use tab to check the possible options for completion it show just items that has the param text in the beginning of the word. 目前在Powershell中,当我使用tab检查可能的完成选项时,它仅显示单词开头带有param文本的项目。

Example: Given the items 示例:给定项目

  • Program Files 程序文件
  • Local Programs 本地程序
  • Another item 另一个项目

When 什么时候

cd Pro [tab]

Returns: 返回:

  • Program Files 程序文件

So, it will show as option all the directories where the name starts with Pro . 因此,它将显示名称以Pro开头的所有目录作为选项。 But I want to change this behavior, instead of the premise "Starting with" I would like a "Contains". 但是我想更改这种行为,而不是前提为“开始于”,而是要“包含”。

In this case my outcome would be: 在这种情况下,我的结果将是:

Example: Given the items 示例:给定项目

  • Program Files 程序文件
  • Local Programs 本地程序
  • Another item 另一个项目

When 什么时候

cd Pro [tab]

Returns: 返回:

  • Program Files 程序文件
  • Local Programs 本地程序

I don't know if there is another way, I would say so, but I solved it with TabExpansion : 我不知道是否还有另一种方法,但是我用TabExpansion解决了:

function TabExpansion($line, $lastWord) {
    if ($line.StartsWith("cd ")) {
        return Get-ChildItem -Name *$lastWord*
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM