mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-16 06:54:03 +00:00
Correctly inherit a virtual PWD
PWD is not set in fish vars because it is read only. Use getenv() to fetch it, allowing fish to inherit a virtual PWD. Fixes #5525
This commit is contained in:
parent
e97c27c177
commit
91a9c98974
4 changed files with 22 additions and 1 deletions
|
@ -1005,7 +1005,11 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
|
||||||
|
|
||||||
// initialize the PWD variable if necessary
|
// initialize the PWD variable if necessary
|
||||||
// Note we may inherit a virtual PWD that doesn't match what getcwd would return; respect that.
|
// Note we may inherit a virtual PWD that doesn't match what getcwd would return; respect that.
|
||||||
if (vars.get(L"PWD").missing_or_empty()) {
|
// Note we treat PWD as read-only so it was not set in vars.
|
||||||
|
const char *incoming_pwd = getenv("PWD");
|
||||||
|
if (incoming_pwd && incoming_pwd[0]) {
|
||||||
|
vars.set_one(L"PWD", ENV_EXPORT | ENV_GLOBAL, str2wcstring(incoming_pwd));
|
||||||
|
} else {
|
||||||
vars.set_pwd_from_getcwd();
|
vars.set_pwd_from_getcwd();
|
||||||
}
|
}
|
||||||
vars.set_termsize(); // initialize the terminal size variables
|
vars.set_termsize(); // initialize the terminal size variables
|
||||||
|
|
|
@ -4,3 +4,6 @@
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# cd symlink completion
|
# cd symlink completion
|
||||||
|
|
||||||
|
####################
|
||||||
|
# Virtual PWD inheritance
|
||||||
|
|
10
tests/cd.in
10
tests/cd.in
|
@ -42,3 +42,13 @@ complete -C'cd ../'
|
||||||
# cd back before removing the test directory again.
|
# cd back before removing the test directory again.
|
||||||
cd $oldpwd
|
cd $oldpwd
|
||||||
rm -Rf $base
|
rm -Rf $base
|
||||||
|
|
||||||
|
logmsg Virtual PWD inheritance
|
||||||
|
# PWD should be imported and respected by fish
|
||||||
|
|
||||||
|
mkdir -p $base/realhome
|
||||||
|
set fish_path $PWD/../test/root/bin/fish
|
||||||
|
ln -s $base/realhome $base/linkhome
|
||||||
|
cd $base/linkhome
|
||||||
|
env HOME=$base/linkhome $fish_path -c 'echo PWD is $PWD'
|
||||||
|
|
||||||
|
|
|
@ -17,3 +17,7 @@ cd:
|
||||||
../a2/
|
../a2/
|
||||||
../a3/
|
../a3/
|
||||||
../rabbithole/
|
../rabbithole/
|
||||||
|
|
||||||
|
####################
|
||||||
|
# Virtual PWD inheritance
|
||||||
|
PWD is /tmp/cdcomp_test/linkhome
|
||||||
|
|
Loading…
Reference in a new issue