Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preliminary support for .project files #149

Merged
merged 3 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ the target virtualenv name, you can manually specify which virtualenv should be
activated for a given project by creating a ``.venv`` file inside the project
root containing the name of the corresponding virtualenv.

If you use sub-folders, have projects located outside of ``PROJECT_HOME``, or
utilize a project organization strategy that does not lend itself to storing
all your projects in the root of a single directory, you may navigate to your
project and associate the current working directory with the currently-activated
virtual environment via the following example steps::

vf activate YourVirtualenv
cd /path/to/your/project
echo $PWD > $VIRTUALENV/.project

In the future, you may then run ``vf workon YourVirtualenv`` to simultaneously
activate ``YourVirtualenv`` and switch to the ``/path/to/your/project``
directory.

Commands
........

Expand Down
34 changes: 24 additions & 10 deletions virtualfish/projects.fish
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ function __vf_workon --description "Work on a project"
# Matches a virtualenv name and possibly a project name
if [ -d $VIRTUALFISH_HOME/$argv[1] ]
vf activate $argv[1]
if [ -d $PROJECT_HOME/$argv[1] ]
if [ -e $VIRTUAL_ENV/.project ]
set -l project_file_path (cat $VIRTUAL_ENV/.project)
if [ -d $project_file_path ]
cd $project_file_path
else
echo ".project file path does not exist: $project_file_path"
return 2
end
else if [ -d $PROJECT_HOME/$argv[1] ]
cd $PROJECT_HOME/$argv[1]
end
# Matches a project name but not a virtualenv name
Expand Down Expand Up @@ -61,14 +69,20 @@ function __vf_lsprojects --description "List projects"
end

function __vf_cdproject --description "Change working directory to project directory"
if [ ! -d $PROJECT_HOME ]
return 2
end

if set -q VIRTUAL_ENV
set -l project_name (basename $VIRTUAL_ENV)
if [ -d $PROJECT_HOME/$project_name ]
cd $PROJECT_HOME/$project_name
if [ -e $VIRTUAL_ENV/.project ]
set -l project_file_path (cat $VIRTUAL_ENV/.project)
if [ -d $project_file_path ]
cd $project_file_path
else
echo ".project file path does not exist: $project_file_path"
return 2
end
else if [ -n "$PROJECT_HOME" ]
set -l project_name (basename $VIRTUAL_ENV)
if [ -d $PROJECT_HOME/$project_name ]
cd $PROJECT_HOME/$project_name
end
end
end
end
Expand All @@ -91,7 +105,7 @@ if set -q VIRTUALFISH_COMPAT_ALIASES
end
end

complete -x -c workon -a "(ls $PROJECT_HOME)"
complete -x -c workon -a "(vf lsprojects)"
end

complete -x -c vf -n '__vfcompletion_using_command workon' -a "(ls $PROJECT_HOME)"
complete -x -c vf -n '__vfcompletion_using_command workon' -a "(vf lsprojects)"