From add214385d40dbdb8896551f8c5e7a3b415080ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Misty=20De=20M=C3=A9o?= Date: Mon, 4 Dec 2023 13:03:41 -0800 Subject: [PATCH] feat: support ZDOTDIR in installer --- .../templates/installer/installer.sh.j2 | 25 +++++++++++++++++-- cargo-dist/tests/gallery/dist.rs | 1 + .../tests/snapshots/akaikatana_basic.snap | 25 +++++++++++++++++-- .../tests/snapshots/akaikatana_musl.snap | 25 +++++++++++++++++-- .../akaikatana_repo_with_dot_git.snap | 25 +++++++++++++++++-- .../tests/snapshots/axolotlsay_abyss.snap | 25 +++++++++++++++++-- .../snapshots/axolotlsay_abyss_only.snap | 25 +++++++++++++++++-- .../tests/snapshots/axolotlsay_basic.snap | 25 +++++++++++++++++-- .../snapshots/axolotlsay_edit_existing.snap | 25 +++++++++++++++++-- .../tests/snapshots/axolotlsay_musl.snap | 25 +++++++++++++++++-- .../snapshots/axolotlsay_musl_no_gnu.snap | 25 +++++++++++++++++-- .../axolotlsay_no_homebrew_publish.snap | 25 +++++++++++++++++-- .../axolotlsay_ssldotcom_windows_sign.snap | 25 +++++++++++++++++-- ...xolotlsay_ssldotcom_windows_sign_prod.snap | 25 +++++++++++++++++-- .../axolotlsay_user_publish_job.snap | 25 +++++++++++++++++-- .../snapshots/install_path_cargo_home.snap | 25 +++++++++++++++++-- .../snapshots/install_path_env_no_subdir.snap | 25 +++++++++++++++++-- .../snapshots/install_path_env_subdir.snap | 25 +++++++++++++++++-- .../install_path_env_subdir_space.snap | 25 +++++++++++++++++-- .../install_path_env_subdir_space_deeper.snap | 25 +++++++++++++++++-- .../install_path_home_subdir_deeper.snap | 25 +++++++++++++++++-- .../install_path_home_subdir_min.snap | 25 +++++++++++++++++-- .../install_path_home_subdir_space.snap | 25 +++++++++++++++++-- ...install_path_home_subdir_space_deeper.snap | 25 +++++++++++++++++-- 24 files changed, 530 insertions(+), 46 deletions(-) diff --git a/cargo-dist/templates/installer/installer.sh.j2 b/cargo-dist/templates/installer/installer.sh.j2 index 39834acf0..c7a41082c 100644 --- a/cargo-dist/templates/installer/installer.sh.j2 +++ b/cargo-dist/templates/installer/installer.sh.j2 @@ -313,6 +313,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -328,11 +346,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -345,7 +365,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/gallery/dist.rs b/cargo-dist/tests/gallery/dist.rs index da61f9baa..da76fcb12 100644 --- a/cargo-dist/tests/gallery/dist.rs +++ b/cargo-dist/tests/gallery/dist.rs @@ -370,6 +370,7 @@ impl DistResult { let app_home = tempdir.join(format!(".{app_name}")); let _output = script.output_checked(|cmd| { cmd.env("HOME", &tempdir) + .env("ZDOTDIR", &tempdir) .env("MY_ENV_VAR", &app_home) .env_remove("CARGO_HOME") })?; diff --git a/cargo-dist/tests/snapshots/akaikatana_basic.snap b/cargo-dist/tests/snapshots/akaikatana_basic.snap index f4f310435..6aa2728ba 100644 --- a/cargo-dist/tests/snapshots/akaikatana_basic.snap +++ b/cargo-dist/tests/snapshots/akaikatana_basic.snap @@ -296,6 +296,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +329,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -328,7 +348,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/akaikatana_musl.snap b/cargo-dist/tests/snapshots/akaikatana_musl.snap index ead899228..a4ca071fa 100644 --- a/cargo-dist/tests/snapshots/akaikatana_musl.snap +++ b/cargo-dist/tests/snapshots/akaikatana_musl.snap @@ -306,6 +306,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -321,11 +339,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -338,7 +358,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/akaikatana_repo_with_dot_git.snap b/cargo-dist/tests/snapshots/akaikatana_repo_with_dot_git.snap index f4f310435..6aa2728ba 100644 --- a/cargo-dist/tests/snapshots/akaikatana_repo_with_dot_git.snap +++ b/cargo-dist/tests/snapshots/akaikatana_repo_with_dot_git.snap @@ -296,6 +296,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +329,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -328,7 +348,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/axolotlsay_abyss.snap b/cargo-dist/tests/snapshots/axolotlsay_abyss.snap index b2c386785..de62187dc 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_abyss.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_abyss.snap @@ -296,6 +296,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +329,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -328,7 +348,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap b/cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap index 7aa28c320..694b82d1b 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap @@ -296,6 +296,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +329,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -328,7 +348,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/axolotlsay_basic.snap b/cargo-dist/tests/snapshots/axolotlsay_basic.snap index 3712fdbd3..94fc68435 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_basic.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_basic.snap @@ -296,6 +296,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +329,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -328,7 +348,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap b/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap index a2e309653..70b61aaf4 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap @@ -296,6 +296,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +329,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -328,7 +348,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/axolotlsay_musl.snap b/cargo-dist/tests/snapshots/axolotlsay_musl.snap index 7dc6a51d6..8ab91d941 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_musl.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_musl.snap @@ -306,6 +306,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -321,11 +339,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -338,7 +358,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap b/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap index e501bb513..8e26c51f4 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap @@ -306,6 +306,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -321,11 +339,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -338,7 +358,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap b/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap index 7171d3496..ef401024e 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap @@ -296,6 +296,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +329,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -328,7 +348,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap b/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap index e43ae2163..3d5f67671 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap @@ -296,6 +296,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +329,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -328,7 +348,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign_prod.snap b/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign_prod.snap index a677daa12..5cc657bb2 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign_prod.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign_prod.snap @@ -296,6 +296,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +329,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -328,7 +348,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap b/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap index ef06ad7e6..6fd60800d 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap @@ -296,6 +296,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +329,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -328,7 +348,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/install_path_cargo_home.snap b/cargo-dist/tests/snapshots/install_path_cargo_home.snap index d7df692d0..41d4dceaa 100644 --- a/cargo-dist/tests/snapshots/install_path_cargo_home.snap +++ b/cargo-dist/tests/snapshots/install_path_cargo_home.snap @@ -296,6 +296,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +329,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -328,7 +348,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/install_path_env_no_subdir.snap b/cargo-dist/tests/snapshots/install_path_env_no_subdir.snap index 65085445c..b8ef3e347 100644 --- a/cargo-dist/tests/snapshots/install_path_env_no_subdir.snap +++ b/cargo-dist/tests/snapshots/install_path_env_no_subdir.snap @@ -279,6 +279,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +312,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -311,7 +331,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/install_path_env_subdir.snap b/cargo-dist/tests/snapshots/install_path_env_subdir.snap index 6b6c1b91c..f92cf22c1 100644 --- a/cargo-dist/tests/snapshots/install_path_env_subdir.snap +++ b/cargo-dist/tests/snapshots/install_path_env_subdir.snap @@ -279,6 +279,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +312,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -311,7 +331,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/install_path_env_subdir_space.snap b/cargo-dist/tests/snapshots/install_path_env_subdir_space.snap index cebb0f61d..4b5167b77 100644 --- a/cargo-dist/tests/snapshots/install_path_env_subdir_space.snap +++ b/cargo-dist/tests/snapshots/install_path_env_subdir_space.snap @@ -279,6 +279,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +312,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -311,7 +331,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/install_path_env_subdir_space_deeper.snap b/cargo-dist/tests/snapshots/install_path_env_subdir_space_deeper.snap index ef7082967..4e535b1fb 100644 --- a/cargo-dist/tests/snapshots/install_path_env_subdir_space_deeper.snap +++ b/cargo-dist/tests/snapshots/install_path_env_subdir_space_deeper.snap @@ -279,6 +279,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +312,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -311,7 +331,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/install_path_home_subdir_deeper.snap b/cargo-dist/tests/snapshots/install_path_home_subdir_deeper.snap index da5a402a0..976138df4 100644 --- a/cargo-dist/tests/snapshots/install_path_home_subdir_deeper.snap +++ b/cargo-dist/tests/snapshots/install_path_home_subdir_deeper.snap @@ -279,6 +279,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +312,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -311,7 +331,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/install_path_home_subdir_min.snap b/cargo-dist/tests/snapshots/install_path_home_subdir_min.snap index acab6f00f..0a18284d5 100644 --- a/cargo-dist/tests/snapshots/install_path_home_subdir_min.snap +++ b/cargo-dist/tests/snapshots/install_path_home_subdir_min.snap @@ -279,6 +279,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +312,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -311,7 +331,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/install_path_home_subdir_space.snap b/cargo-dist/tests/snapshots/install_path_home_subdir_space.snap index 0727065c7..f0a0a7468 100644 --- a/cargo-dist/tests/snapshots/install_path_home_subdir_space.snap +++ b/cargo-dist/tests/snapshots/install_path_home_subdir_space.snap @@ -279,6 +279,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +312,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -311,7 +331,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. diff --git a/cargo-dist/tests/snapshots/install_path_home_subdir_space_deeper.snap b/cargo-dist/tests/snapshots/install_path_home_subdir_space_deeper.snap index 3de2db1a0..b4e6ca7cc 100644 --- a/cargo-dist/tests/snapshots/install_path_home_subdir_space_deeper.snap +++ b/cargo-dist/tests/snapshots/install_path_home_subdir_space_deeper.snap @@ -279,6 +279,24 @@ install() { fi } +print_home_for_script() { + local script="$1" + + local _home + case "$script" in + # zsh has a special ZDOTDIR directory, which if set + # should be considered instead of $HOME + .zsh*) + _home="$(zsh -c 'if [ -n "$ZDOTDIR" ]; then echo $ZDOTDIR; else echo $HOME; fi')" + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +312,13 @@ add_install_dir_to_path() { if [ -n "${HOME:-}" ]; then local _target + local _home # Find the first file in the array that exists and choose # that as our target to write to for _rcfile_relative in $_rcfiles; do - local _rcfile="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + local _rcfile="$_home/$_rcfile_relative" if [ -f "$_rcfile" ]; then _target="$_rcfile" @@ -311,7 +331,8 @@ add_install_dir_to_path() { if [ -z "${_target:-}" ]; then local _rcfile_relative _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" - _target="$HOME/$_rcfile_relative" + _home="$(print_home_for_script "$_rcfile_relative")" + _target="$_home/$_rcfile_relative" fi # `source x` is an alias for `. x`, and the latter is more portable/actually-posix.