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