Reputation: 490
I am using Windows Terminal(Preview) with shells like 1.PowerShell, 2.WSL
in my Windows 10 machine. I installed the latest version of oh-my-posh
and posh-git
to customize the terminal. My current theme is Agnoster
which gives a colorful custom prompt. But I want to get rid of the "username@host" from my prompt.
Eg:
Current => username@host D:\folder-name>
Needed => D:\folder-name>
I tried few things with $GitPromptSettings
variable and also in GitPrompt.ps1
file which is inside the posh-git folder but with no use.
Also, since i have oh-my-posh and posh-git, does both have prompt customization properties or it is only from posh-git?
Any help is appreciated.
Upvotes: 7
Views: 6193
Reputation: 5746
In Oh My Posh 3, the method for hiding the username@host
part has changed because the whole theme configuration has changed.
The username@host
portion of the powerline comes from the "session"
segment. The configuration options for session
can be found here: https://ohmyposh.dev/docs/session
Interesting options are:
display_user: boolean
- display the user name or not - defaults to true
display_host: boolean
- display the host name or not - defaults to true
default_user_name: string
- name of the default user - defaults to emptydisplay_default: boolean
- display the segment or not when the user matches default_user_name
- defaults to true
And the note on environment variables:
POSH_SESSION_DEFAULT_USER
- used to override the hardcodeddefault_user_name
property
Based on this, I made the following changes:
display_default: false
property to the "session"
segment:
{
"type": "session",
// ....
"properties": {
"display_default": false
}
}```
$env:POSH_SESSION_DEFAULT_USER = [System.Environment]::UserName
This makes the user@host
part of the prompt disappear as long as I'm using my default username.
Upvotes: 6
Reputation: 81
remove the segment which type is session from ~\Documents\WindowsPowerShell\Modules\oh-my-posh\3.101.23\themes\<themename>.omp.json
Upvotes: 8
Reputation: 91
You have to set $DefaultUser before importing modules.
Example:
$global:DefaultUser = [System.Environment]::UserName
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox
Upvotes: 7
Reputation: 91
You may check {theme's name}.psm1
in the Themes/ directory to understand how it works.
The key is the following code.
e.g. Paradox.psm1
$user = $sl.CurrentUser
....
if (Test-NotDefaultUser($user)) {
$prompt += Write-Prompt -Object "$user@$computer " -ForegroundColor $sl.Colors.SessionInfoForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
}
if $DefaultUser
is same to $user
or is different $null
, your powershell does not show $user@$computer
.
Upvotes: 2