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