Skip to content

Commit 5b08637

Browse files
authored
Merge pull request #222023 from theJasonHelmick/enabling-predictions
Enabling Predictive IntelliSense with Az.Tools.Predictor
2 parents 3c60b15 + cb313b2 commit 5b08637

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed

articles/cloud-shell/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ items:
3939
href: embed-cloud-shell.md
4040
- name: Cloud Shell in an Azure virtual network
4141
href: private-vnet.md
42+
- name: Predictive IntelliSense in Cloud Shell
43+
href: cloud-shell-predictive-intellisense.md
4244
- name: Use the Cloud Shell editor
4345
href: using-cloud-shell-editor.md
4446
- name: Troubleshooting
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
---
2+
title: Predictive IntelliSense in Azure Cloud Shell
3+
description: Azure Cloud Shell uses Predictive IntelliSense
4+
services: Azure
5+
documentationcenter: ''
6+
author: theJasonHelmick
7+
manager: mgreene
8+
9+
ms.service: cloud-shell
10+
ms.workload: infrastructure-services
11+
ms.tgt_pltfrm: vm-linux
12+
ms.topic: article
13+
ms.date: 10/11/2022
14+
ms.author: jahelmic
15+
---
16+
17+
# Predictive IntelliSense in Azure Cloud Shell
18+
19+
Beginning January 2023 Azure Cloud Shell uses the version of [PSReadLine][01] that has Predictive
20+
IntelliSense enabled by default. We've also installed and enabled the Azure PowerShell predictor
21+
[Az.Tools.Predictor][02]] module. Together, these changes enhance the command-line experience by
22+
providing suggestions that help new and experienced users of Azure discover, edit, and execute
23+
complete commands.
24+
25+
## What is Predictive IntelliSense?
26+
27+
Predictive IntelliSense is a feature of the **PSReadLine** module. It provides suggestions for
28+
complete commands based on items from your history and from predictor modules, like
29+
**Az.Tools.Predictor**.
30+
31+
Prediction suggestions appear as colored text following the user's cursor. The following image shows
32+
the default `InlineView` of the suggestion. Pressing <kbd>RightArrow</kbd> key accepts an inline
33+
suggestion. After accepting the suggestion, you can edit the command line before hitting
34+
<kbd>Enter</kbd> to run the command.
35+
36+
![Suggestion in InlineView mode](./media/predictive-intellisense/cloud-shell-inline.png)
37+
38+
PSReadLine also offers a `ListView` presentation of the suggestions.
39+
40+
![Suggestions in ListView mode](./media/predictive-intellisense/cloud-shell-list-view.png)
41+
42+
In `ListView` mode, use the arrow keys to scroll through the available suggestions. List view also
43+
shows the source of the prediction.
44+
45+
You can switch between `InlineView` and `ListView` by pressing the <kbd>F2</kbd> key.
46+
47+
## How to change the prediction color
48+
49+
The default color of the suggestions may be difficult for some people. **PSReadLine** allows you to
50+
configure the color of the suggestions.
51+
52+
The following command changes the color of inline suggestions to white text on a gray background.
53+
54+
```powershell
55+
Set-PSReadLineOption -Colors @{ InlinePrediction = $PSStyle.Foreground.White + $PSStyle.Background.BrightBlack }
56+
```
57+
58+
Learn more about color settings for [Set-PSReadLineOption][03].
59+
60+
## How to disable Predictive IntelliSense
61+
62+
If you don't want to take advantage of these updated features, **PSReadLine** allows you to turn off
63+
Predictive IntelliSense.
64+
65+
To disable Predictive IntelliSense, execute the following `Set-PSReadLineOption` command or add to
66+
the PowerShell profile script.
67+
68+
```powershell
69+
Set-PSReadLineOption -PredictionSource None
70+
```
71+
72+
## Keep your changes permanent
73+
74+
The commands to change the prediction color and enable or disable predictions only affect the
75+
current session. Add these commands to your PowerShell profile so that they're available every time
76+
you start Cloud Shell. The following instructions will guide you through configuring a profile for
77+
Cloud Shell. For more information on PowerShell profiles, see [About_Profiles][06]
78+
79+
### How to check if you have a PowerShell profile in Cloud Shell
80+
81+
A PowerShell profile is a script that runs when PowerShell starts. Use `Test-Path` to check if the
82+
profile exists in Cloud Shell.
83+
84+
```powershell
85+
Test-Path -Path $Profile
86+
```
87+
88+
### How to Create a PowerShell profile in Cloud Shell
89+
90+
If the output is **False**, create a profile and add the customized color and behavior commands.
91+
92+
To store configuration commands for Predictive IntelliSense, Use the `New-Item` cmdlet to create a
93+
PowerShell profile.
94+
95+
```powershell
96+
New-Item -Path $Profile -ItemType File -Force
97+
```
98+
99+
```output
100+
101+
Directory: /home/jason/.config/PowerShell
102+
103+
UnixMode User Group LastWriteTime Size Name
104+
-------- ---- ----- ------------- ---- ----
105+
-rw-r--r-- jason jason 11/19/2022 18:21 0 Microsoft.PowerShell_profile.ps1
106+
```
107+
108+
Use the built-in open-source editor to edit the profile. To learn more, see [Azure Cloud Shell editor][04].
109+
110+
The following example shows the profile commands that set the prediction color to default light grey
111+
and enables History predictions.
112+
113+
```powershell
114+
Set-PSReadLineOption -PredictionSource History
115+
Set-PSReadLineOption -Colors @{ InLinePrediction = '#8d8d8d' }
116+
```
117+
118+
### How to Edit a PowerShell profile in Cloud Shell
119+
120+
If the output is **True**, then a profile already exists. Edit the existing profile to add the
121+
commands to configure the color and behavior of Predictive IntelliSense. Use the built-in
122+
open-source editor to edit the profile. To learn more, see [Azure Cloud Shell editor][04].
123+
124+
Use the built-in Cloud Shell editor to edit the profile:
125+
126+
```powershell
127+
Code $Profile
128+
```
129+
130+
## Next steps
131+
132+
For more information about configuring PSReadLine and managing predictors, see
133+
[Using predictors in PSReadLine][05].
134+
135+
For more information on PowerShell profiles, see [About_Profiles][06].
136+
137+
138+
<!-- link references -->
139+
[01]: /powershell/module/psreadline/about/about_psreadline
140+
[02]: /powershell/azure/az-predictor
141+
[03]: /powershell/module/psreadline/set-psreadlineoption
142+
[04]: /azure/cloud-shell/using-cloud-shell-editor
143+
[05]: /powershell/scripting/learn/shell/using-predictors
144+
[06]: /powershell/module/microsoft.powershell.core/about/about_profiles
145+
52 KB
Loading
236 KB
Loading

0 commit comments

Comments
 (0)