From 5ed91080ea21492b7217f3bda3a5e0bdc9b97b1c 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..8de87ee31 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 # @@ -332,7 +350,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..9ac932924 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 # @@ -315,7 +333,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..4ba549320 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 # @@ -325,7 +343,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..9ac932924 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 # @@ -315,7 +333,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..025c757f1 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 # @@ -315,7 +333,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..b8b2d2147 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 # @@ -315,7 +333,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..fb9df15aa 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 # @@ -315,7 +333,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..2179acdbd 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 # @@ -315,7 +333,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..3ed7c4bff 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 # @@ -325,7 +343,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..42123814b 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 # @@ -325,7 +343,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..411297627 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 # @@ -315,7 +333,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..6500f329f 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 # @@ -315,7 +333,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..883d0ebd2 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 # @@ -315,7 +333,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..5d0bd2359 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 # @@ -315,7 +333,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..9b926cddd 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 # @@ -315,7 +333,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..62daf1963 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 # @@ -298,7 +316,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..b88249a38 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 # @@ -298,7 +316,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..520d8aa90 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 # @@ -298,7 +316,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..f182d7ab8 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 # @@ -298,7 +316,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..f8916fb08 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 # @@ -298,7 +316,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..6cdc895be 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 # @@ -298,7 +316,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..ff4f6427f 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 # @@ -298,7 +316,9 @@ add_install_dir_to_path() { # 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" + local _home + _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..9d721a99b 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 # @@ -298,7 +316,9 @@ add_install_dir_to_path() { # 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" + local _home + _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.