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

Support .project files in virtualenvs if they are available #134

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
docs/_build
.eggs
52 changes: 40 additions & 12 deletions virtualfish/projects.fish
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ function __vf_workon --description "Work on a project"
if [ -d $PROJECT_HOME/$argv[1] ]
cd $PROJECT_HOME/$argv[1]
end
if test -e $VIRTUAL_ENV/.project
cd (cat $VIRTUAL_ENV/.project)
end
# Matches a project name but not a virtualenv name
else if [ -d $PROJECT_HOME/$argv[1] ]
set -l project_name $argv[1]
Expand All @@ -34,15 +37,35 @@ function __vf_workon --description "Work on a project"
end

function __vf_project --description "Create a new project and virtualenv with the name provided"
set -l project_name $argv[-1]
set -l project_path "$PROJECT_HOME/$project_name"
if [ -d $project_path ]
echo "A project with that name already exists at: $project_path"
return 2
else
vf new $argv
mkdir -p $project_path
cd $project_path
set -l options "(fish_opt --short a --required)"
# kill stderr as argparse throws errors on unknonw parameters
argparse --name 'vf project' $options -- $argv ^/dev/null

if test -z $_flag_a # no porject path given, use plugin standard project path
set -l project_name $argv[-1]
set -l project_path "$PROJECT_HOME/$project_name"
if [ -d $project_path ]
echo "A project with that name already exists at: $project_path"
return 2
else
vf new $argv
mkdir -p $project_path
cd $project_path
end
else if vf new $argv # -a $project_path given
cd $_flag_a
and pwd >?$VIRTUAL_ENV/.project
end
end

functions --copy __vf_new __vf__new_projects_original
function __vf_new --wraps=__vf_new
set -l options (fish_opt --short a --required)
# kill stderr as argparse throws errors on unknonw parameters
argparse --name 'vf new' $options -- $argv ^/dev/null
if __vf__new_projects_original $argv; and test -n $_flag_a
cd $_flag_a
and pwd >?$VIRTUAL_ENV/.project
end
end

Expand All @@ -61,10 +84,15 @@ function __vf_lsprojects --description "List projects"
end

function __vf_cdproject --description "Change working directory to project directory"

if test -e $VIRTUAL_ENV/.project
cd (cat $VIRTUAL_ENV/.project)
return
end

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 ]
Expand All @@ -91,7 +119,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)"
1 change: 1 addition & 0 deletions virtualfish/virtual.fish
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function __vf_activate --description "Activate a virtualenv"

emit virtualenv_did_activate
emit virtualenv_did_activate:(basename $VIRTUAL_ENV)

end

function __vf_deactivate --description "Deactivate this virtualenv"
Expand Down