Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak prompt logic in example profile #11390

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions reference/docs-conceptual/learn/shell/creating-profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description: >
This article explains how to use your profile to save preferred PowerShell settings and optimize
your shell experience.
ms.date: 12/01/2022
ms.date: 09/04/2024
title: Customizing your shell environment
---
# Customizing your shell environment
Expand Down Expand Up @@ -109,12 +109,13 @@ function prompt {
$principal = [Security.Principal.WindowsPrincipal] $identity
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator

$prefix = $(if (Test-Path variable:/PSDebugContext) { '[DBG]: ' }
elseif ($principal.IsInRole($adminRole)) { "[ADMIN]: " }
else { '' })
$body = 'PS ' + $(Get-Location)
$prefix = if (Test-Path variable:/PSDebugContext) { '[DBG]: ' } else { '' }
if ($principal.IsInRole($adminRole)) {
$prefix = "[ADMIN]:$prefix"
}
$body = 'PS ' + $PWD.path
$suffix = $(if ($NestedPromptLevel -ge 1) { '>>' }) + '> '
$prefix + $body + $suffix
"${prefix}${body}${suffix}"
}

## Create $PSStyle if running on a version older than 7.2
Expand Down