Skip to content

Commit 5392e7d

Browse files
authored
Merge pull request phpbrew#1030 from morozov/fish-phpbrewrc
Fixed handing of .phpbrewrc in Fish
2 parents 186ee90 + ad01a5c commit 5392e7d

File tree

2 files changed

+37
-42
lines changed

2 files changed

+37
-42
lines changed

shell/bashrc

+3-3
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,15 @@ function _phpbrewrc_load ()
479479
return
480480
fi
481481
local curr_dir="$PWD"
482-
local prev_dir="$OLDPWD"
482+
local prev_dir=""
483483
local curr_fs=0
484484
local prev_fs=0
485485

486486
while [[ -n "$curr_dir" && -d "$curr_dir" ]] ; do
487487
prev_fs=$curr_fs
488-
curr_fs=$(stat -c %d . 2>/dev/null) # GNU version
488+
curr_fs=$(stat -c %d "$curr_dir" 2>/dev/null) # GNU version
489489
if [ $? -ne 0 ]; then
490-
curr_fs=$(stat -f %d . 2>/dev/null) # BSD version
490+
curr_fs=$(stat -f %d "$curr_dir" 2>/dev/null) # BSD version
491491
fi
492492

493493
# check if top level directory or filesystem boundary is reached

shell/phpbrew.fish

+34-39
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function phpbrew
170170
set chdir $PHPBREW_ROOT/php/$PHPBREW_PHP/var
171171
case etc
172172
set chdir $PHPBREW_ROOT/php/$PHPBREW_PHP/etc
173-
cas dist
173+
case dist
174174
set chdir $PHPBREW_ROOT/php/$PHPBREW_PHP
175175
case build
176176
set chdir $PHPBREW_ROOT/build/$PHPBREW_PHP
@@ -426,53 +426,48 @@ if begin ; [ -n "$PHPBREW_SET_PROMPT" ]; and [ "$PHPBREW_SET_PROMPT" = "1" ]; en
426426
# non supports in fish now
427427
end
428428

429-
function _phpbrewrc_load
430-
# check if working dir has changed
431-
if [ "$PWD" != "$PHPBREW_LAST_DIR" ]
432-
set -l curr_dir "$PWD"
433-
set -l prev_dir "$OLDPWD"
434-
set -l curr_fs 0
435-
set -l prev_fs 0
436-
437-
while true
438-
set prev_fs $curr_fs
439-
set curr_fs (stat -c %d . ^/dev/null) # GNU version
440-
if [ $status -ne 0 ]
441-
# the original curr_fs
442-
# set curr_fs (stat -f %d . ^/dev/null) # BSD version
443-
set curr_fs (stat -f %d . >/dev/null ^&1) # BSD version
444-
end
429+
function _phpbrewrc_load --on-variable PWD --description 'Load configuration based on .phpbrewrc'
430+
set -q PHPBREW_RC_ENABLE
431+
or return
432+
433+
status --is-command-substitution;
434+
and return
435+
436+
set curr_dir "$PWD"
437+
set prev_dir ""
438+
set curr_fs 0
439+
set prev_fs 0
445440

446-
# check if top level directory or filesystem boundary is reached
447-
if begin; [ "$PWD" = '/' ]; or [ -z "$PHPBREW_RC_DISCOVERY_ACROSS_FILESYSTEM" -a $prev_fs -ne 0 -a $curr_fs -ne $prev_fs ]; end
441+
while [ -n "$curr_dir" -a -d "$curr_dir" ]
442+
set prev_fs $curr_fs
443+
set curr_fs (stat -c %d "$curr_dir" ^/dev/null) # GNU version
444+
if [ $status -ne 0 ]
445+
set curr_fs (stat -f %d "$curr_dir" >/dev/null ^&1) # BSD version
446+
end
447+
448+
# check if top level directory or filesystem boundary is reached
449+
if begin; [ "$curr_dir" = "/" ]; or [ -z "$PHPBREW_RC_DISCOVERY_ACROSS_FILESYSTEM" -a $prev_fs -ne 0 -a $curr_fs -ne $prev_fs ]; end
450+
# check if there's a previously loaded .phpbrewrc
451+
if [ ! -z "$PHPBREW_LAST_RC_DIR" ]
448452
set -e PHPBREW_LAST_RC_DIR
449453
__phpbrew_load_user_config
450-
break
451454
end
455+
break
456+
end
452457

453-
# check if .phpbrewrc present
454-
if [ -r .phpbrewrc ]
455-
# check if it's not the same .phpbrewrc which was previously loaded
456-
if [ "$PWD" != "$PHPBREW_LAST_RC_DIR" ]
457-
__phpbrew_load_user_config
458-
set PHPBREW_LAST_RC_DIR "$PWD"
459-
source .phpbrewrc
460-
end
461-
break
458+
# check if .phpbrewrc present
459+
if [ -r "$curr_dir/.phpbrewrc" ]
460+
# check if it's not the same .phpbrewrc which was previously loaded
461+
if [ "$curr_dir" != "$PHPBREW_LAST_RC_DIR" ]
462+
__phpbrew_load_user_config
463+
set -g PHPBREW_LAST_RC_DIR "$curr_dir"
464+
source "$curr_dir/.phpbrewrc"
462465
end
463-
464-
cd .. ^ /dev/null ; or break
466+
break
465467
end
466468

467-
cd "$curr_dir"
468-
set OLDPWD "$prev_dir"
469+
set curr_dir (dirname "$curr_dir")
469470
end
470-
471-
set PHPBREW_LAST_DIR "$PWD"
472-
end
473-
474-
if begin ; [ -n "$BASH_VERSION" ]; and [ -z "$PHPBREW_RC_DISABLE" ]; end
475-
trap "_phpbrewrc_load" DEBUG
476471
end
477472

478473
###

0 commit comments

Comments
 (0)