Skip to content

Instantly share code, notes, and snippets.

@PARC6502
Last active June 17, 2022 13:16
Show Gist options
  • Save PARC6502/c35a771cd35b6325af6fdad76d39a985 to your computer and use it in GitHub Desktop.
Save PARC6502/c35a771cd35b6325af6fdad76d39a985 to your computer and use it in GitHub Desktop.
Shorten the path in the PowerShell prompt if it's too long
function prompt {
$path = $pwd
$path_arr = $path.path.Split("\")
if ($path_arr.count -gt 4)
{
$path = @($path_arr[0], "..." + $path_arr[-3,-2,-1]) -join "\"
}
'PS ' + $path + '> '
}

An adjustment to the PowerShell prompt function that limits the number of path components. In this case the limit is 4 components.

If there are more than four components the components between the first one and the last three are replaced with "...".

It is similar to what the PROMPT_DIRTRIM environment variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment