Skip to content

Commit

Permalink
Fix usage of double slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
dasJ committed Aug 26, 2016
1 parent 8b88d89 commit ae84a55
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 8 additions & 1 deletion activate.sh
Expand Up @@ -2,14 +2,20 @@ AUTOENV_AUTH_FILE="${AUTOENV_AUTH_FILE:-$HOME/.autoenv_authorized}"
AUTOENV_ENV_FILENAME="${AUTOENV_ENV_FILENAME:-.env}"

autoenv_init() {
local _mountpoint _files _orderedfiles
local _mountpoint _files _orderedfiles _sedregexp
if [ "${OSTYPE#darwin*}" != "${OSTYPE}" ]; then
_mountpoint="`df "${PWD}" | awk 'END{print $NF}'`"
_sedregexp='-E'
else
_mountpoint="`stat -c '%m' \"${PWD}\"`"
_sedregexp='-r'
fi
# Remove double slashes, see #125
PWD="`echo "${PWD}" | sed "${_sedregexp}" 's:/+:/:g'`"
command -v chdir >/dev/null 2>&1 && chdir "${PWD}" || builtin cd "${PWD}"
# Discover all files we need to source
# We do this in a subshell so we can cd/chdir
set -x
_files="`
_hadone=''
while [ "${PWD}" != "${_mountpoint}" ]; do
Expand All @@ -26,6 +32,7 @@ ${_file}"
command -v chdir >/dev/null 2>&1 && chdir .. || builtin cd ..
done
`"
set +x

# ZSH: Use traditional for loop
zsh_shwordsplit="$( setopt > /dev/null 2>&1 | grep -q shwordsplit && echo 1 )"
Expand Down
21 changes: 21 additions & 0 deletions tests/test_doubleslash.sh
@@ -0,0 +1,21 @@
. "${FUNCTIONS}"
. "${ACTIVATE_SH}"

# Prepare files/directories
mkdir -pv 'a/b' 'c/d'
echo 'echo a' > "a/.env"
echo 'echo b' > "a/b/.env"
echo 'echo c' > "c/.env"

# Test simple cd
patterntest 'echo "Y" | cd a/' '.*a$'
# Test absolute cd
patterntest "echo "Y" | cd /${PWD}/a/" '.*a$'
# Test cd to subdirectory
( echo "Y" | cd a/b )
patterntest 'echo "Y" | cd a//b/' '.*a
b$'
# Test cd with env in parent directory
patterntest 'echo "Y" | cd c//d/' '.*c$'
# Check cd into nonexistent directory
echo "Y" | cd d// && exit 1 || :

0 comments on commit ae84a55

Please sign in to comment.