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) |
Bram Moolenaar | 130cbfc | 2021-04-07 21:07:20 +0200 | [diff] [blame] | 6 | |
| 7 | " Only do this when not done yet for this buffer |
| 8 | if exists("b:did_ftplugin") | finish | endif |
| 9 | |
| 10 | " Don't load another plug-in for this buffer |
| 11 | let b:did_ftplugin = 1 |
| 12 | |
| 13 | let s:cpo_save = &cpo |
| 14 | set cpo&vim |
| 15 | |
| 16 | setlocal tw=0 |
| 17 | setlocal commentstring=#%s |
| 18 | setlocal formatoptions=tcqro |
| 19 | " Enable autocompletion of hyphenated PowerShell commands, |
| 20 | " e.g. Get-Content or Get-ADUser |
| 21 | setlocal iskeyword+=- |
| 22 | |
Doug Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 23 | " Change the browse dialog on Win32 and GTK to show mainly PowerShell-related files |
| 24 | if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") |
Bram Moolenaar | 130cbfc | 2021-04-07 21:07:20 +0200 | [diff] [blame] | 25 | 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 Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 29 | \ "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 Moolenaar | 130cbfc | 2021-04-07 21:07:20 +0200 | [diff] [blame] | 35 | endif |
| 36 | |
| 37 | " Look up keywords by Get-Help: |
| 38 | " check for PowerShell Core in Windows, Linux or MacOS |
| 39 | if executable('pwsh') | let s:pwsh_cmd = 'pwsh' |
| 40 | " on Windows Subsystem for Linux, check for PowerShell Core in Windows |
| 41 | elseif exists('$WSLENV') && executable('pwsh.exe') | let s:pwsh_cmd = 'pwsh.exe' |
| 42 | " check for PowerShell <= 5.1 in Windows |
| 43 | elseif executable('powershell.exe') | let s:pwsh_cmd = 'powershell.exe' |
| 44 | endif |
| 45 | |
| 46 | if 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 |
| 56 | endif |
| 57 | setlocal keywordprg=:GetHelp |
| 58 | |
| 59 | " Undo the stuff we changed |
| 60 | let b:undo_ftplugin = "setlocal tw< cms< fo< iskeyword< keywordprg<" . |
| 61 | \ " | unlet! b:browsefilter" |
| 62 | |
| 63 | let &cpo = s:cpo_save |
| 64 | unlet s:cpo_save |