leifdenby
leifdenby

Reputation: 1468

Zsh PROJECT environment variable

I've been trying to find out how to set the directory for a rope project for ropevim to find automatically (I still haven't succeeded in this), and in doing this I have discovered the $PROJECT environment variable in zsh.

Once I set this variable to a specific path, for instance the root of my project

~ # cd my_project_folder
~/my_project_folder # export PROJECT=`pwd`

The prompt is changed so that all paths are printed as relative to PROJECT, the project root, like so

PROJECT # cd sub_folder
PROJECT/sub_folder #

which is pretty neat as it shortens the path, but I would like to change the prompt to display for instance the project name instead of PROJECT.

I have tried to search the zsh documentation for any mention of this environment variable, but no luck. Has anyone encountered this variable before? bash seems to ignore this environment variable.

Upvotes: 0

Views: 1626

Answers (1)

simont
simont

Reputation: 72527

You could probably make use of a project specific named directory.

For example, with a directory structure:

~/projects/foo
~/projects/foo/bar

in your ~/.zshrc:

FOO=~/projects/foo

your prompt could look similar to this:

 ~/projects  #ls
foo
 ~/projects  #cd foo 
 ~FOO  #ls
 bar
 ~/FOO  #cd bar
 ~/FOO/bar  #

This uses %~ to expand the current directory within the prompt:

As %d and %/, but if the current working directory has a named directory as its prefix, that part is replaced by a ~ followed by the name of the directory.

(found under "SIMPLE PROMPT ESCAPES" in the linked man zshmisc page).

Upvotes: 1

Related Questions