justinmayer / virtualfish

Fish shell tool for managing Python virtual environments
MIT License
1.07k stars 101 forks source link

`vf install` should quote paths #252

Closed cthoyt closed 6 days ago

cthoyt commented 1 week ago

Issue

I installed virtualfish using the following:

$ uv tool install virtualfish
$ vf install

Then, I got the following error when either trying to re-source or open a new terminal:

$ exec fish
source: Error encountered while sourcing file '/Users/cthoyt/Library/Application':
source: No such file or directory

I took a look in my ~/.config/fish/conf.d/virtualfish-loader.fish which had the following:

set -g VIRTUALFISH_VERSION 2.5.9
set -g VIRTUALFISH_PYTHON_EXEC /Users/cthoyt/Library/Application Support/uv/tools/virtualfish/bin/python
source /Users/cthoyt/Library/Application Support/uv/tools/virtualfish/lib/python3.11/site-packages/virtualfish/virtual.fish
emit virtualfish_did_setup_plugins

Manual Fix

I was able to fix the issue and return virtualfish to normal working order by quoting the file paths in the second and third lines as in the following:

set -g VIRTUALFISH_VERSION 2.5.9
set -g VIRTUALFISH_PYTHON_EXEC "/Users/cthoyt/Library/Application Support/uv/tools/virtualfish/bin/python"
source "/Users/cthoyt/Library/Application Support/uv/tools/virtualfish/lib/python3.11/site-packages/virtualfish/virtual.fish"
emit virtualfish_did_setup_plugins

Requested update

I think that virtualfish's install command can be improved to determine when quoting is necessary on a path that has spaces, such as ones on MacOS where the python binary might be inside an Application Support subfolder

The two lines to update for my specific situation

https://github.com/justinmayer/virtualfish/blob/0cff4b87cfc3ee72e984cc43e2acbf48a180a597/virtualfish/loader/__init__.py#L19-L20

And related, for any plugins:

https://github.com/justinmayer/virtualfish/blob/0cff4b87cfc3ee72e984cc43e2acbf48a180a597/virtualfish/loader/__init__.py#L28