문제

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.

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top