sdkman / sdkman-hooks

An API responsible for serving up pre- and post- hooks
Other
5 stars 23 forks source link

Feature: Append sdkman_init_snippet only when profile-file exists #59

Open carlosdgomez opened 2 years ago

carlosdgomez commented 2 years ago

Feature request

The following code is creating a .zshrc file in systems without zsh installed:

echo "Attempt update of zsh profile..."
touch "$sdkman_zshrc"
if [[ -z $(grep 'sdkman-init.sh' "$sdkman_zshrc") ]]; then
    echo -e "\n$sdkman_init_snippet" >> "$sdkman_zshrc"
    echo "Updated existing ${sdkman_zshrc}"
fi

To avoid that behavior, a condition to check if the file exists will allow the file not to be created with touch and sdkman_init_snippet to only be added when the file exists:

echo "Attempt update of zsh profile..."
if [[ -e "$sdkman_zshrc" && -z $(grep 'sdkman-init.sh' "$sdkman_zshrc") ]]; then
    echo -e "\n$sdkman_init_snippet" >> "$sdkman_zshrc"
    echo "Updated existing ${sdkman_zshrc}"
fi

Files to be refactored

Comments

Same strategy should be used for the other profile-files being supported so as to keep consistency.