robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #40931 from zeertzjq/vim-9.2.0839e4137a7324

master
2.6 KiB65 linesraw
1" Vim filetype plugin file
2" Language:    Windows PowerShell
3" URL:         https://github.com/PProvost/vim-ps1
4" Last Change: 2021 Apr 02
5"              2024 Jan 14 by Vim Project (browsefilter)
6"              2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring')
7"              2024 Sep 19 by Konfekt (simplify keywordprg #15696)
8"              2025 Jul 22 by phanium (use :hor term #17822)
9"              2026 Jul 10 by Vim Project (quote K argument, prevent command injection)
10
11" Only do this when not done yet for this buffer
12if exists("b:did_ftplugin") | finish | endif
13
14" Don't load another plug-in for this buffer
15let b:did_ftplugin = 1
16
17let s:cpo_save = &cpo
18set cpo&vim
19
20setlocal tw=0
21setlocal commentstring=#\ %s
22setlocal formatoptions=tcqro
23" Enable autocompletion of hyphenated PowerShell commands,
24" e.g. Get-Content or Get-ADUser
25setlocal iskeyword+=-
26
27" Change the browse dialog on Win32 and GTK to show mainly PowerShell-related files
28if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
29	let b:browsefilter =
30				\ "All PowerShell Files (*.ps1, *.psd1, *.psm1, *.ps1xml)\t*.ps1;*.psd1;*.psm1;*.ps1xml\n" .
31				\ "PowerShell Script Files (*.ps1)\t*.ps1\n" .
32				\ "PowerShell Module Files (*.psd1, *.psm1)\t*.psd1;*.psm1\n" .
33				\ "PowerShell XML Files (*.ps1xml)\t*.ps1xml\n"
34	if has("win32")
35		let b:browsefilter .= "All Files (*.*)\t*\n"
36	else
37		let b:browsefilter .= "All Files (*)\t*\n"
38	endif
39endif
40
41" Undo the stuff we changed
42let b:undo_ftplugin = "setlocal tw< cms< fo< iskeyword<" .
43			\ " | unlet! b:browsefilter"
44
45" Look up keywords by Get-Help:
46" check for PowerShell Core in Windows, Linux or MacOS
47if executable('pwsh') | let s:pwsh_cmd = 'pwsh'
48  " on Windows Subsystem for Linux, check for PowerShell Core in Windows
49elseif exists('$WSLENV') && executable('pwsh.exe') | let s:pwsh_cmd = 'pwsh.exe'
50  " check for PowerShell <= 5.1 in Windows
51elseif executable('powershell.exe') | let s:pwsh_cmd = 'powershell.exe'
52endif
53
54if exists('s:pwsh_cmd')
55  if exists(':terminal') == 2
56    command! -buffer -nargs=1 GetHelp call term_start([s:pwsh_cmd, '-NoLogo', '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'RemoteSigned', '-Command', "Get-Help -Full '" . substitute(<q-args>, "'", "''", 'g') . "'" . (executable('less') ? ' | less' : '')])
57  else
58    command! -buffer -nargs=1 GetHelp echo system([s:pwsh_cmd, '-NoLogo', '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'RemoteSigned', '-Command', "Get-Help -Full '" . substitute(<q-args>, "'", "''", 'g') . "'"])
59  endif
60  setlocal keywordprg=:GetHelp
61  let b:undo_ftplugin ..= " | setl kp< | sil! delc -buffer GetHelp"
62endif
63
64let &cpo = s:cpo_save
65unlet s:cpo_save