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