blob: e09bbf86dca9ed304f978d41e7f354401fb130b5 [file] [log] [blame]
Bram Moolenaar130cbfc2021-04-07 21:07:20 +02001" Vim filetype plugin file
2" Language: Windows PowerShell
3" URL: https://github.com/PProvost/vim-ps1
4" Last Change: 2021 Apr 02
Doug Kearns93197fd2024-01-14 20:59:02 +01005" 2024 Jan 14 by Vim Project (browsefilter)
Riley Bruins0a083062024-06-03 20:40:45 +02006" 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring')
Konfektf86568f2024-09-19 19:34:40 +02007" 2024 Sep 19 by Konfekt (simplify keywordprg #15696)
Bram Moolenaar130cbfc2021-04-07 21:07:20 +02008
9" Only do this when not done yet for this buffer
10if exists("b:did_ftplugin") | finish | endif
11
12" Don't load another plug-in for this buffer
13let b:did_ftplugin = 1
14
15let s:cpo_save = &cpo
16set cpo&vim
17
18setlocal tw=0
Riley Bruins0a083062024-06-03 20:40:45 +020019setlocal commentstring=#\ %s
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020020setlocal formatoptions=tcqro
21" Enable autocompletion of hyphenated PowerShell commands,
22" e.g. Get-Content or Get-ADUser
23setlocal iskeyword+=-
24
Doug Kearns93197fd2024-01-14 20:59:02 +010025" Change the browse dialog on Win32 and GTK to show mainly PowerShell-related files
26if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020027 let b:browsefilter =
28 \ "All PowerShell Files (*.ps1, *.psd1, *.psm1, *.ps1xml)\t*.ps1;*.psd1;*.psm1;*.ps1xml\n" .
29 \ "PowerShell Script Files (*.ps1)\t*.ps1\n" .
30 \ "PowerShell Module Files (*.psd1, *.psm1)\t*.psd1;*.psm1\n" .
Doug Kearns93197fd2024-01-14 20:59:02 +010031 \ "PowerShell XML Files (*.ps1xml)\t*.ps1xml\n"
32 if has("win32")
33 let b:browsefilter .= "All Files (*.*)\t*\n"
34 else
35 let b:browsefilter .= "All Files (*)\t*\n"
36 endif
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020037endif
38
Konfektf86568f2024-09-19 19:34:40 +020039" Undo the stuff we changed
40let b:undo_ftplugin = "setlocal tw< cms< fo< iskeyword<" .
41 \ " | unlet! b:browsefilter"
42
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020043" Look up keywords by Get-Help:
44" check for PowerShell Core in Windows, Linux or MacOS
45if executable('pwsh') | let s:pwsh_cmd = 'pwsh'
46 " on Windows Subsystem for Linux, check for PowerShell Core in Windows
47elseif exists('$WSLENV') && executable('pwsh.exe') | let s:pwsh_cmd = 'pwsh.exe'
48 " check for PowerShell <= 5.1 in Windows
49elseif executable('powershell.exe') | let s:pwsh_cmd = 'powershell.exe'
50endif
51
52if exists('s:pwsh_cmd')
Konfektf86568f2024-09-19 19:34:40 +020053 if exists(':terminal') == 2
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020054 command! -buffer -nargs=1 GetHelp silent exe 'term ' . s:pwsh_cmd . ' -NoLogo -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command Get-Help -Full "<args>"' . (executable('less') ? ' | less' : '')
55 else
56 command! -buffer -nargs=1 GetHelp echo system(s:pwsh_cmd . ' -NoLogo -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command Get-Help -Full <args>')
57 endif
Konfektf86568f2024-09-19 19:34:40 +020058 setlocal keywordprg=:GetHelp
59 let b:undo_ftplugin ..= " | setl kp< | sil! delc -buffer GetHelp"
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020060endif
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020061
62let &cpo = s:cpo_save
63unlet s:cpo_save