Since I have been working with some PowerShell modules that consist of several .ps1 files (in addition to the .psm1 file), I was curious as to whether ctags could work with PowerShell.
There were two problems, easily fixed.
The first was in the command line to add PowerShell to ctags:
The regex doesn’t include ‘-‘, so it won’t recognize a whole lot of functions….
The other problem was in the .cnf file:
--langdef=powershell --langmap=powershell:.ps1 --langmap=powershell:.psm1
That did not work; the .ps1 files were not recognized, as though the .psm1 line was overwriting the previous assignment.
Looking at the ctags documentation, I learned that this is a way to do it:
My complete ctags.cnf (stored in $env:USERPROFILE):
--langdef=powershell --langmap=powershell:.ps1.psm1 --regex-powershell=/^function[\t ]*([a-zA-Z0-9_-]+)/\1/d,definition/ --regex-powershell=/^filter[\t ]*([a-zA-Z0-9_-]+)/\1/d,definition/ --regex-powershell=/^set-alias[\t ]*([a-zA-Z0-9_-]+)/\1/d,definition/
(Unfortunately, aliases are not recognized yet.)
To use, open a console and navigate to a directory with some PowerShell files.
Here’s the command I use:
> ctags.exe –append=yes –verbose=yes -f p:\tags –tag-relative=yes *
(Run “ctags –help” for all command line switches.)
In using this at work I discovered that ctags (and maybe gvim) doesn’t work well with UNC paths. I wanted to put my tags file in “\\corp\hdq\data2\ZZZ CMM\2 WPDB\2.03 Application Material\NBA_NB_2014\Support\PowerShell”, but that didn’t work, so I mapped P: to that path and it worked as expected.
… and Bob’s your uncle.
Very handy for navigating within the .psm1/.ps1 components of a PowerShell module.