From 9bb596addc1e415d46a8e3f2e0288a020992a909 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Fri, 13 Nov 2020 15:42:29 -0800 Subject: [PATCH 1/3] Document tab-completion --- pages/developer/other_commands.md | 2 +- pages/developer/tab_completion.md | 51 +++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 pages/developer/tab_completion.md 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..c9946f49 --- /dev/null +++ b/pages/developer/tab_completion.md @@ -0,0 +1,51 @@ +--- +layout: page +title: Everyday commands +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 From 70cf9d0cb09de4c1a8e420c0c5c295a0c8c1d4c8 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Mon, 16 Nov 2020 10:34:11 -0800 Subject: [PATCH 2/3] Change page title to 'Tab completion' --- pages/developer/tab_completion.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/developer/tab_completion.md b/pages/developer/tab_completion.md index c9946f49..a9e34511 100644 --- a/pages/developer/tab_completion.md +++ b/pages/developer/tab_completion.md @@ -1,6 +1,6 @@ --- layout: page -title: Everyday commands +title: Tab completion navigation_source: docs_nav --- From 3110e8cacff7504ea03798ffc4225fa88e4759a1 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Wed, 18 Nov 2020 11:55:01 -0800 Subject: [PATCH 3/3] Add a new entry in navigation.yaml --- _data/navigation.yaml | 2 ++ 1 file changed, 2 insertions(+) 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: