8

I am running windows terminal and it's great. But there are two settings that I would like to change:

  1. I would like to change the prompt to something shorter. By default, the prompt displays the current working directory. It tends to get very long and it clutters my terminal.

  2. It's still valuable to know the current working directory at a glance, of course, so I'd like to place it in the title bar.

I see that I can create a "prompt" function in my powershell profile. I'd hesitate to just change it to PS>. Hoping that there's something more clever and ready-to-use? I'd like to avoid going down a deep rabbit hole of ms docs just to fix my prompt.

Looking at settings.json (here's the schema), there happens to be a setting for TabTitle, but it appears to just take a string. Is it possible to enter an expression that supplies the pwd? ¯\_(ツ)_/¯

"tabTitle": {
  "description": "If set, will replace the name as the title to pass to the shell on startup. Some shells (like bash) may choose to ignore this initial value, while others (cmd, powershell) may use this value over the lifetime of the application.",
  "type": [
    "string",
    "null"
  ]
},

1 Answer 1

6

Several options:

  • You could abbreviate the prompt to just show the short directory name, rather than the full path as in this answer.

  • I know that some Linux shells and prompts like to abbreviate using the first character of each path element. That could be done by using something like ((Get-Location).toString().split("\") -replace '^(.).*','$1' -join '\') + '> ' in the prompt function.

  • You might consider using a prompt utility like Starship that can do a number of prompt customizations using configuration rather than code.

  • Updating the tab title in PowerShell/Windows Terminal is done through setting $Host.UI.RawUI.WindowTitle.

Put it all together, and you might end up with something like:

function prompt {
  $Host.UI.RawUI.WindowTitle = "$pwd"
  ((Get-Location).toString().split("\") -replace '^(.).*','$1' -join '\') + '> '
}
1
  • 1
    Very nice... kept trying to use $PWD :). Commented Feb 23 at 18:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .