About the hooks.ps1
- Each completion has a
hooks.ps1file, which is used to dynamically add completion items. - It needs to provide a
handleCompletionsfunction. - The function will receive a parameter
$completions, which is an array containing all completion items parsed from json. - The function needs to return a new array, which will be used as the final completion data by
PSCompletions.
- If
config.jsondoes not definehooks, it will never be called. - Only when
config.jsondefineshooksand meets the following conditions will it be called:hooksistrue, and has not been disabled bypsc completion xxx enable_hooks 0hooksisfalse, but has been enabled bypsc completion xxx enable_hooks 1
powershell
function handleCompletions($completions) {
$list = @()
# $input_arr = $PSCompletions.input_arr
$filter_input_arr = $PSCompletions.filter_input_arr # Without -*
# switch ($filter_input_arr[-1]) {
# 'add' {
# $list += $PSCompletions.return_completion('aaa', "Add aaa")
# }
# }
$list += $PSCompletions.return_completion('example', "It's from hooks")
return $list + $completions
}TIP
- The function
$PSCompletions.return_completionis used to add new completion items. - The first parameter is the completion item name.
- The second parameter is the completion item help(tip).
- The third parameter is optional, used to specify the special symbol of the completion item.
SpaceTab:~OptionTab:?WriteSpaceTab:!