Skip to content

Instantly share code, notes, and snippets.

@acast15
Last active March 13, 2022 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acast15/5dc2158dddf78af8427c7f8a6dc08d2d to your computer and use it in GitHub Desktop.
Save acast15/5dc2158dddf78af8427c7f8a6dc08d2d to your computer and use it in GitHub Desktop.
Add this function to your PowerShell profile so you won't see the full path of the working directory on the prompt. Once you've configured your profile, restart PowerShell and try any of the options for the prompt.
function demo {
param (
[parameter()]
[ValidateSet('v', 'n', 'r')]
[string]$Option = 'v'
)
switch ($Option) {
# hide PS version
'n' {
function global:prompt { "PS > " }
}
# reset prompt
'r' {
function global:prompt { "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) " }
}
# show PS version
'v' {
function global:prompt { "PS$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor) > " }
}
}
}
# Change prompt to "PS [version] >"
#demo demo v
# Change prompt to "PS >"
#demo n
# Reset prompt
#demo r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment