diff --git a/_data/navigation.yaml b/_data/navigation.yaml index 719add12..12b19da4 100644 --- a/_data/navigation.yaml +++ b/_data/navigation.yaml @@ -38,6 +38,8 @@ docs_nav: url: /pages/developer/modifying_package_json - title: Other helpful commands url: /pages/developer/other_commands + - title: Tab completion + url: /pages/developer/tab_completion - title: Maintainer tutorials subitems: diff --git a/pages/developer/other_commands.md b/pages/developer/other_commands.md index 123f4296..b86f2819 100644 --- a/pages/developer/other_commands.md +++ b/pages/developer/other_commands.md @@ -36,5 +36,5 @@ $ rush unlink $ rush purge ``` -#### Next up: [How to get help]({% link pages/help/support.md %}) +#### Next up: [Tab completion]({% link pages/developer/tab_completion.md %}) diff --git a/pages/developer/tab_completion.md b/pages/developer/tab_completion.md new file mode 100644 index 00000000..a9e34511 --- /dev/null +++ b/pages/developer/tab_completion.md @@ -0,0 +1,51 @@ +--- +layout: page +title: Tab completion +navigation_source: docs_nav +--- + +# Tab completion for the Rush CLI + +Inspired by [Tab completion for the .NET Core CLI](https://docs.microsoft.com/en-us/dotnet/core/tools/enable-tab-autocomplete). + +**NOTE**: the globally installed version of `Rush` will need to be at least `5.34.0`. + +## PowerShell +To add tab completion to PowerShell for the Rush CLI, create or edit the profile stored in the variable `$PROFILE`. For more information, see [How to create your profile](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles#how-to-create-a-profile) and [Profiles and execution policy](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles#profiles-and-execution-policy). + +Add the following code to your profile: + +```powershell +# PowerShell parameter completion shim for the Rush CLI +Register-ArgumentCompleter -Native -CommandName rush -ScriptBlock { + param($commandName, $wordToComplete, $cursorPosition) + rush tab-complete --position $cursorPosition --word "$wordToComplete" | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) + } + } +``` + +## Bash +To add tab completion to your bash shell for the Rush CLI, add the following code to your .bashrc file: +```bash +# bash parameter completion for the Rush CLI + +_rush_bash_complete() +{ + local word=${COMP_WORDS[COMP_CWORD]} + + local completions + completions="$(rush tab-complete --position "${COMP_POINT}" --word "${COMP_LINE}" 2>/dev/null)" + if [ $? -ne 0 ]; then + completions="" + fi + + COMPREPLY=( $(compgen -W "$completions" -- "$word") ) +} + +complete -f -F _rush_bash_complete rush +``` + + + +#### Next up: [How to get help]({% link pages/help/support.md %}) \ No newline at end of file