diff --git a/src/segments/path.go b/src/segments/path.go index a72b4ac5..edf02069 100644 --- a/src/segments/path.go +++ b/src/segments/path.go @@ -23,6 +23,7 @@ type Path struct { StackCount int Location string Writable bool + RootDir bool } const ( @@ -427,6 +428,9 @@ func (pt *Path) replaceMappedLocations() (string, string) { sort.Sort(sort.Reverse(sort.StringSlice(keys))) root, relative := pt.parsePath(pt.pwd) + if len(relative) == 0 { + pt.RootDir = true + } rootN := pt.normalize(root) relativeN := pt.normalize(relative) pathSeparator := pt.env.PathSeparator() diff --git a/website/docs/segments/path.mdx b/website/docs/segments/path.mdx index b539ed7e..72ddbf07 100644 --- a/website/docs/segments/path.mdx +++ b/website/docs/segments/path.mdx @@ -64,13 +64,13 @@ For example, to swap out `C:\Users\Leet\GitHub` with a GitHub icon, you can do t ### Notes - To make mapped locations work cross-platform, use `/` as the path separator, Oh My Posh will -automatically match effective separators based on the running operating system. + automatically match effective separators based on the running operating system. - If you want to match all child directories, you can use `*` as a wildcard, for example: -`"C:/Users/Bill/*": "$"` will turn `C:/Users/Bill/Downloads` into `$/Downloads`. + `"C:/Users/Bill/*": "$"` will turn `C:/Users/Bill/Downloads` into `$/Downloads`. - The character `~` at the start of a mapped location will match the user's home directory. - The match is case-insensitive on Windows and macOS, but case-sensitive on other operating systems. This means that for -user Bill, who has a user account `Bill` on Windows and `bill` on Linux, `~/Foo` might match -`C:\Users\Bill\Foo` or `C:\Users\Bill\foo` on Windows but only `/home/bill/Foo` on Linux. + user Bill, who has a user account `Bill` on Windows and `bill` on Linux, `~/Foo` might match + `C:\Users\Bill\Foo` or `C:\Users\Bill\foo` on Windows but only `/home/bill/Foo` on Linux. ## Style @@ -151,9 +151,10 @@ folders at the same level, so if `C:\projectA\dev` and `C:\projectB\dev` exist, ### Properties | Name | Type | Description | -| ------------- | --------- | ---------------------------------------------------------------------------- | +| ------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `.Path` | `string` | the current directory (based on the `style` property) | | `.Parent` | `string` | the current directory's parent folder which ends with a path separator (designed for use with style `folder`, it is empty if `.Path` contains only one single element) | +| `.RootDir` | `boolean` | true if we're at the root directory (no parent) | | `.Location` | `string` | the current directory (raw value) | | `.StackCount` | `int` | the stack count | | `.Writable` | `boolean` | is the current directory writable by the user or not |