Frage

I have setup several repositories and I have one symbolic link which points to the current working directory. The problem I face sometimes is when looking at the path in prompt it shows the symbolic link and sometimes I end up building wrong repository.

This is the directory structure -
| Repo 1
| Repo 2
| repository-> Repo 1

and this is how my prompt looks like somewhat- /home/rishi/repository$ ...

what I think would be really nice If the soft links could show their target along with their name. Something like -

/home/rishi/repository(Repo 1)$ ...

I tried to search but couldn't find anything on how to do this? Can someone point me to right direction?

I am using zsh shell.

War es hilfreich?

Lösung

This does it, PROMPT_SUBST turns on shell code evaluation from inside the prompt

setopt PROMPT_SUBST
function getBasename() {
  if [[ -h $PWD ]]; then
   printf "("`readlink $PWD`") "
  fi
}

export PROMPT='%~ $(getBasename)%# ' # must use single quotes here
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top