Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New] install.sh: add $ZDOTDIR to zsh search #3458

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ nvm_detect_profile() {
DETECTED_PROFILE="$HOME/.bash_profile"
fi
elif [ "${SHELL#*zsh}" != "$SHELL" ]; then
if [ -f "$HOME/.zshrc" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
elif [ -f "$HOME/.zprofile" ]; then
DETECTED_PROFILE="$HOME/.zprofile"
if [ -f "${ZDOTDIR:-${HOME}}/.zshrc" ]; then
DETECTED_PROFILE="${ZDOTDIR:-${HOME}}/.zshrc"
elif [ -f "${ZDOTDIR:-${HOME}}/.zprofile" ]; then
DETECTED_PROFILE="${ZDOTDIR:-${HOME}}/.zprofile"
fi
fi

Expand Down
33 changes: 29 additions & 4 deletions test/install_script/nvm_detect_profile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
setup () {
HOME="."
NVM_ENV=testing \. ../../install.sh
ZDOTDIR="$HOME/zdotdir"
mkdir -p zdotdir
touch ".bashrc"
touch ".bash_profile"
touch ".zprofile"
touch ".zshrc"
touch ".profile"
touch "test_profile"
touch "zdotdir/.zshrc"
touch "zdotdir/.zprofile"
}

cleanup () {
Expand All @@ -17,7 +21,9 @@ cleanup () {
unset NVM_DETECT_PROFILE
unset SHELL
unset -f setup cleanup die
unset ZDOTDIR
rm -f ".bashrc" ".bash_profile" ".zprofile" ".zshrc" ".profile" "test_profile" > "/dev/null" 2>&1
rm -rf zdot>&1
}

die () { echo "$@" '$NVM_DETECT_PROFILE:' "$NVM_DETECT_PROFILE"; cleanup; exit 1; }
Expand Down Expand Up @@ -46,8 +52,14 @@ if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then
die "nvm_detect_profile ignored \$PROFILE"
fi

# .zshrc should be detected for zsh
# zdotdir/.zshrc should be detected for zsh
NVM_DETECT_PROFILE="$(SHELL="/bin/zsh"; unset PROFILE; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$ZDOTDIR/.zshrc" ]; then
die "nvm_detect_profile didn't pick \$ZDOTDIR/.zshrc for zsh"
fi

# .zshrc should be detected for zsh
NVM_DETECT_PROFILE="$(SHELL="/bin/zsh"; unset PROFILE; unset ZDOTDIR; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then
die "nvm_detect_profile didn't pick \$HOME/.zshrc for zsh"
fi
Expand All @@ -58,7 +70,6 @@ if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then
die "nvm_detect_profile ignored \$PROFILE"
fi


#
# Confirm $PROFILE is only returned when it points to a valid file
#
Expand Down Expand Up @@ -102,16 +113,30 @@ if [ "$NVM_DETECT_PROFILE" != "$HOME/.bash_profile" ]; then
die "nvm_detect_profile should have selected .bash_profile"
fi

# Otherwise, it should favor .zprofile if file exists
# Otherwise, it should favor zdotdir/.zprofile if file exists
rm ".bash_profile"
NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$ZDOTDIR/.zprofile" ]; then
die "nvm_detect_profile should have selected zdotdir/.zprofile"
fi

# Otherwise, it should favor .zprofile if file exists
rm "zdotdir/.zprofile"
NVM_DETECT_PROFILE="$(unset SHELL; unset ZDOTDIR; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$HOME/.zprofile" ]; then
die "nvm_detect_profile should have selected .zprofile"
fi

# Otherwise, it should favor .zshrc if file exists
# Otherwise, it should favor zdotdir/.zshrc if file exists
rm ".zprofile"
NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$ZDOTDIR/.zshrc" ]; then
die "nvm_detect_profile should have selected zdotdir/.zshrc"
fi

# Otherwise, it should favor .zshrc if file exists
rm "zdotdir/.zshrc"
NVM_DETECT_PROFILE="$(unset SHELL; unset ZDOTDIR; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then
die "nvm_detect_profile should have selected .zshrc"
fi
Expand Down
Loading