0

I'm using WSL to run ohmyzsh on my win 10 machine. I have a repository folder in which I keep my git repositories, and it is my most common working directory. I want to be able to conditionally hide the prompt working directory that comes before this folder.

Currently it looks like this: PWD with long path due to WSL mounting

I instead want it to resemble the following: jl@EDEN-WKS-JL > .../repos/react-POC, replacing anything before repos with a ..., but obviously only doing this if repos is in the PWD.

I've tried using the answer provided this question on AskUbuntu (Trim the terminal command prompt working directory), but I could not get the answer to work, so that I could modify it for my needs. As I want it to be conditional based on a particular folder, and I'm not in bash, I don't think I can use the PROMPT_DIRTRIM bash variable.

How can I conditionally trim the PWD in zsh, based on the contents of the PWD?

Update

I've tried setting the following in ~/.zshrc, while it does mostly work, it breaks the styling. (also this is the first time I've used sed, so this could likely be improved)

PS1=$(echo $PWD | sed 's/\(.*\/repos\)/~\/...\/repos/')

truncated path, but broken styling

J Lewis
  • 111

0 Answers0