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