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
  • 5
  • Which theme are you using in zsh? Those are prompt text and can be changed with `PS1` environment variable in RC file, like .bahsrc, .zshrc etc. Or change the theme that zsh is using. – Biswapriyo Nov 13 '19 at 13:09
  • agnoster theme, I'll add my progress to the question – J Lewis Nov 13 '19 at 13:22
  • Try some simple ones, here are the list https://github.com/robbyrussell/oh-my-zsh/wiki/External-themes – Biswapriyo Nov 13 '19 at 13:24

0 Answers0