blob: 9d698f24235771d13ee714dd240af494dbee4c0b [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')
Bram Moolenaar130cbfc2021-04-07 21:07:20 +02007
8" Only do this when not done yet for this buffer
9if exists("b:did_ftplugin") | finish | endif
10
11" Don't load another plug-in for this buffer
12let b:did_ftplugin = 1
13
14let s:cpo_save = &cpo
15set cpo&vim
16
17setlocal tw=0
Riley Bruins0a083062024-06-03 20:40:45 +020018setlocal commentstring=#\ %s
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020019setlocal formatoptions=tcqro
20" Enable autocompletion of hyphenated PowerShell commands,
21" e.g. Get-Content or Get-ADUser
22setlocal iskeyword+=-
23
Doug Kearns93197fd2024-01-14 20:59:02 +010024" Change the browse dialog on Win32 and GTK to show mainly PowerShell-related files
25if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020026 let b:browsefilter =
27 \ "All PowerShell Files (*.ps1, *.psd1, *.psm1, *.ps1xml)\t*.ps1;*.psd1;*.psm1;*.ps1xml\n" .
28 \ "PowerShell Script Files (*.ps1)\t*.ps1\n" .
29 \ "PowerShell Module Files (*.psd1, *.psm1)\t*.psd1;*.psm1\n" .
Doug Kearns93197fd2024-01-14 20:59:02 +010030 \ "PowerShell XML Files (*.ps1xml)\t*.ps1xml\n"
31 if has("win32")
32 let b:browsefilter .= "All Files (*.*)\t*\n"
33 else
34 let b:browsefilter .= "All Files (*)\t*\n"
35 endif
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020036endif
37
38" Look up keywords by Get-Help:
39" check for PowerShell Core in Windows, Linux or MacOS
40if executable('pwsh') | let s:pwsh_cmd = 'pwsh'
41 " on Windows Subsystem for Linux, check for PowerShell Core in Windows
42elseif exists('$WSLENV') && executable('pwsh.exe') | let s:pwsh_cmd = 'pwsh.exe'
43 " check for PowerShell <= 5.1 in Windows
44elseif executable('powershell.exe') | let s:pwsh_cmd = 'powershell.exe'
45endif
46
47if exists('s:pwsh_cmd')
48 if !has('gui_running') && executable('less') &&
49 \ !(exists('$ConEmuBuild') && &term =~? '^xterm')
50 " For exclusion of ConEmu, see https://github.com/Maximus5/ConEmu/issues/2048
51 command! -buffer -nargs=1 GetHelp silent exe '!' . s:pwsh_cmd . ' -NoLogo -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command Get-Help -Full "<args>" | ' . (has('unix') ? 'LESS= less' : 'less') | redraw!
52 elseif has('terminal')
53 command! -buffer -nargs=1 GetHelp silent exe 'term ' . s:pwsh_cmd . ' -NoLogo -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command Get-Help -Full "<args>"' . (executable('less') ? ' | less' : '')
54 else
55 command! -buffer -nargs=1 GetHelp echo system(s:pwsh_cmd . ' -NoLogo -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command Get-Help -Full <args>')
56 endif
57endif
58setlocal keywordprg=:GetHelp
59
60" Undo the stuff we changed
61let b:undo_ftplugin = "setlocal tw< cms< fo< iskeyword< keywordprg<" .
62 \ " | unlet! b:browsefilter"
63
64let &cpo = s:cpo_save
65unlet s:cpo_save