fix(venv): make relocatable activation scripts support ksh (#5640)

It transpires that detecting the directory a script was sourced from is
non-trivial across `bash`, `ksh` and `zsh`.

The previous version was a one-liner and supported `bash` and `zsh` but
not `ksh`.

It is possible to keep the one-liner and add `ksh` support, but that is
mutually-exclusive with `zsh`.

Therefore, the only way to square this circle is to add an `if` block. A
silver lining here is that although longer, the script is probably
easier to follow as there is less code-golfing going on.
This commit is contained in:
Pavel Dikov 2024-07-31 17:18:11 +01:00 committed by GitHub
parent f266fb711c
commit d05f2b258b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 26 additions and 8 deletions

View file

@ -298,7 +298,7 @@ pub(crate) fn create(
(true, "activate") => {
// Extremely verbose, but should cover all major POSIX shells,
// as well as platforms where `readlink` does not implement `-f`.
r#"'"$(dirname -- "$(CDPATH= cd -- "$(dirname -- ${BASH_SOURCE[0]:-${(%):-%x}})" && echo "$PWD")")"'"#
r#"'"$(dirname -- "$(CDPATH= cd -- "$(dirname -- "$SCRIPT_PATH")" > /dev/null && echo "$PWD")")"'"#
}
(true, "activate.bat") => r"%~dp0..",
(true, "activate.fish") => {