Search code examples
windowspowershellautomation

What character could be use to identify personal powershell scripts?


In his brilliant talk Activation Energy, Brandon Rhodes recommend starting all your scripts with a comma character (,) so they are easy to search with the shell autocomplete.

In the Linux context it might work, but on Windows Powershell (7), starting a script name with ,myscript.psy don't seems to be recognized by the autocomplete (typing , +TAB won't do anything).

What character could be used to achieve the same purpose?
How do you identify your script?


Solution

  • I'm assuming that you're talking about scripts located in a directory listed in $env:PATH, i.e scripts you can call by name only, from any working directory.

    • By contrast, scripts located in the current directory can be tab-completed with , + Tab (e.g., tab-completing script ,foo.ps1 in the current directory turns into & '.\,foo.ps1' (the quoting is necessary due to the nonstandard name, and the quoting in turn requires use of &, the call operator).

    For $env:PATH-based scripts , does not work, as you've experienced, and the only alternatives I can think of are:

    • _

    • ^

    At least on an English keyboard, neither is as convenient to type as , due to requiring leaving the home row of the keyboard and pressing Shift.