JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
16.67k stars 2.34k forks source link

Adaptative Git Path #5341

Closed ebiscaia closed 1 month ago

ebiscaia commented 1 month ago

Code of Conduct

What would you like to see added?

Hi guys,

I would like to when I am inside a git folder, the path to be started from the git root. So I would have three conditions: If I am inside a system folder, the path would look like: /this/is/a/folder If inside home: ~/this/is/a/folder If inside a git folder: <git_folder>/this/is/a/folder

I would prefer also that to be compatible/implemented with Agnoster short, so that long paths would show only the root/home/ and the final folder. The idea is to mimic this behaviour (See 'Adaptive (git and home) (TYPEWRITTEN_RELATIVE_PATH="adaptive")' section).

Thanks,

vagabondHustler commented 1 month ago

Do you mean this? https://github.com/JanDeDobbeleer/oh-my-posh/discussions/5186

JanDeDobbeleer commented 1 month ago

@vagabondHustler exactly what I was about to reply!

@holopin-bot @vagabondHustler helping

holopin-bot[bot] commented 1 month ago

Congratulations @vagabondHustler, the maintainer of this repository has issued you a badge! Here it is: https://holopin.io/claim/clz1l9o1h50660cjs2z4f11e0

This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!

ebiscaia commented 1 month ago

Thanks everyone for the help. The version in the other post led me to what I wanted. Here is my version:

- type: rprompt
  segments:
  - type: path
    style: plain
    foreground: magenta
    template: "{{ if .Segments.Git.Dir }}<i>{{ .Segments.Git.RepoName }}</i>{{ if eq .Path .Segments.Git.Dir }}{{ else if eq (trimSuffix \"/\" .Parent) .Segments.Git.Dir }}/{{.Folder}}{{else}}/../{{.Folder}}{{end}}{{ else }}{{ .Path  }}{{ end }}"
    properties:
      style: agnoster_short
ebiscaia commented 1 month ago

This solution does not completely work because with agnoster_short a .Path is rendered ~/../folder whereas .Segments.Git.Dir renders ~/this/is/a/folder which are then considered different folders.

Some possible solutions:

for now I changed from agnoster_short to full as at least the git repos will show me the path in relation to the git root.

Cheers