From 851b67e362a152e808da4e41431a0ef26f3e1ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Misty=20De=20M=C3=A9o?= Date: Tue, 7 Nov 2023 16:07:36 -0800 Subject: [PATCH 1/3] feat(installer): add additional shell config ~/.profile isn't sourced in many circumstances; we need to write this to a large number of locations to make sure it gets considered by bash and zsh under the largest number of circumstances. We have three sets of configuration files, covering generic POSIX, bash, and zsh. We pick the first file that exists in each set, and if none exists, we create the first in the list. Fixes #547. --- .../templates/installer/installer.sh.j2 | 38 +++++++++++++++---- .../tests/snapshots/akaikatana_basic.snap | 38 +++++++++++++++---- .../tests/snapshots/akaikatana_musl.snap | 38 +++++++++++++++---- .../akaikatana_repo_with_dot_git.snap | 38 +++++++++++++++---- .../tests/snapshots/axolotlsay_abyss.snap | 38 +++++++++++++++---- .../snapshots/axolotlsay_abyss_only.snap | 38 +++++++++++++++---- .../tests/snapshots/axolotlsay_basic.snap | 38 +++++++++++++++---- .../snapshots/axolotlsay_edit_existing.snap | 38 +++++++++++++++---- .../tests/snapshots/axolotlsay_musl.snap | 38 +++++++++++++++---- .../snapshots/axolotlsay_musl_no_gnu.snap | 38 +++++++++++++++---- .../axolotlsay_no_homebrew_publish.snap | 38 +++++++++++++++---- .../axolotlsay_ssldotcom_windows_sign.snap | 38 +++++++++++++++---- ...xolotlsay_ssldotcom_windows_sign_prod.snap | 38 +++++++++++++++---- .../axolotlsay_user_publish_job.snap | 38 +++++++++++++++---- .../snapshots/install_path_cargo_home.snap | 38 +++++++++++++++---- .../snapshots/install_path_env_no_subdir.snap | 38 +++++++++++++++---- .../snapshots/install_path_env_subdir.snap | 38 +++++++++++++++---- .../install_path_env_subdir_space.snap | 38 +++++++++++++++---- .../install_path_env_subdir_space_deeper.snap | 38 +++++++++++++++---- .../install_path_home_subdir_deeper.snap | 38 +++++++++++++++---- .../install_path_home_subdir_min.snap | 38 +++++++++++++++---- .../install_path_home_subdir_space.snap | 38 +++++++++++++++---- ...install_path_home_subdir_space_deeper.snap | 38 +++++++++++++++---- 23 files changed, 713 insertions(+), 161 deletions(-) diff --git a/cargo-dist/templates/installer/installer.sh.j2 b/cargo-dist/templates/installer/installer.sh.j2 index d60b4c41f..39834acf0 100644 --- a/cargo-dist/templates/installer/installer.sh.j2 +++ b/cargo-dist/templates/installer/installer.sh.j2 @@ -48,7 +48,7 @@ then unpacks the binaries and installs them to {% if install_path.kind == "Cargo {{ error("unimplemented install_path format: " ~ install_path.kind) }} {%- endif %} -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: {{ app_name }}-installer.sh [OPTIONS] @@ -307,7 +307,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -322,8 +324,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -349,14 +373,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" diff --git a/cargo-dist/tests/snapshots/akaikatana_basic.snap b/cargo-dist/tests/snapshots/akaikatana_basic.snap index d5ac78439..f4f310435 100644 --- a/cargo-dist/tests/snapshots/akaikatana_basic.snap +++ b/cargo-dist/tests/snapshots/akaikatana_basic.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/mistydemeo/akaikatana-repack/releases/download/v0.2.0 then unpacks the binaries and installs them to \$CARGO_HOME/bin (\$HOME/.cargo/bin) -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: akaikatana-repack-installer.sh [OPTIONS] @@ -290,7 +290,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -305,8 +307,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -332,14 +356,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" diff --git a/cargo-dist/tests/snapshots/akaikatana_musl.snap b/cargo-dist/tests/snapshots/akaikatana_musl.snap index 4154ddb2d..ead899228 100644 --- a/cargo-dist/tests/snapshots/akaikatana_musl.snap +++ b/cargo-dist/tests/snapshots/akaikatana_musl.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/mistydemeo/akaikatana-repack/releases/download/v0.2.0 then unpacks the binaries and installs them to \$CARGO_HOME/bin (\$HOME/.cargo/bin) -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: akaikatana-repack-installer.sh [OPTIONS] @@ -300,7 +300,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -315,8 +317,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -342,14 +366,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" 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 d5ac78439..f4f310435 100644 --- a/cargo-dist/tests/snapshots/akaikatana_repo_with_dot_git.snap +++ b/cargo-dist/tests/snapshots/akaikatana_repo_with_dot_git.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/mistydemeo/akaikatana-repack/releases/download/v0.2.0 then unpacks the binaries and installs them to \$CARGO_HOME/bin (\$HOME/.cargo/bin) -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: akaikatana-repack-installer.sh [OPTIONS] @@ -290,7 +290,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -305,8 +307,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -332,14 +356,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" diff --git a/cargo-dist/tests/snapshots/axolotlsay_abyss.snap b/cargo-dist/tests/snapshots/axolotlsay_abyss.snap index 0b2cdd200..b2c386785 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_abyss.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_abyss.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://fake.axo.dev/faker/axolotlsay/fake-id-do-not-upload then unpacks the binaries and installs them to \$CARGO_HOME/bin (\$HOME/.cargo/bin) -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -290,7 +290,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -305,8 +307,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -332,14 +356,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" diff --git a/cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap b/cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap index aae2cc50a..7aa28c320 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://fake.axo.dev/faker/axolotlsay/fake-id-do-not-upload then unpacks the binaries and installs them to \$CARGO_HOME/bin (\$HOME/.cargo/bin) -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -290,7 +290,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -305,8 +307,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -332,14 +356,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" diff --git a/cargo-dist/tests/snapshots/axolotlsay_basic.snap b/cargo-dist/tests/snapshots/axolotlsay_basic.snap index 1a270b6ec..3712fdbd3 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_basic.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_basic.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$CARGO_HOME/bin (\$HOME/.cargo/bin) -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -290,7 +290,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -305,8 +307,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -332,14 +356,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" diff --git a/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap b/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap index 55e633a44..a2e309653 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$CARGO_HOME/bin (\$HOME/.cargo/bin) -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -290,7 +290,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -305,8 +307,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -332,14 +356,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" diff --git a/cargo-dist/tests/snapshots/axolotlsay_musl.snap b/cargo-dist/tests/snapshots/axolotlsay_musl.snap index ce09f627d..7dc6a51d6 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_musl.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_musl.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$CARGO_HOME/bin (\$HOME/.cargo/bin) -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -300,7 +300,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -315,8 +317,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -342,14 +366,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" diff --git a/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap b/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap index 202cb06d8..e501bb513 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$CARGO_HOME/bin (\$HOME/.cargo/bin) -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -300,7 +300,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -315,8 +317,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -342,14 +366,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" diff --git a/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap b/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap index deeb45f91..7171d3496 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$CARGO_HOME/bin (\$HOME/.cargo/bin) -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -290,7 +290,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -305,8 +307,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -332,14 +356,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" diff --git a/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap b/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap index 4aa6075ff..e43ae2163 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$CARGO_HOME/bin (\$HOME/.cargo/bin) -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -290,7 +290,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -305,8 +307,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -332,14 +356,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" 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 3ee6c8bca..a677daa12 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign_prod.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign_prod.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$CARGO_HOME/bin (\$HOME/.cargo/bin) -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -290,7 +290,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -305,8 +307,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -332,14 +356,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" diff --git a/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap b/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap index 04e2cc7f1..ef06ad7e6 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$CARGO_HOME/bin (\$HOME/.cargo/bin) -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -290,7 +290,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -305,8 +307,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -332,14 +356,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" diff --git a/cargo-dist/tests/snapshots/install_path_cargo_home.snap b/cargo-dist/tests/snapshots/install_path_cargo_home.snap index d2eb25d35..d7df692d0 100644 --- a/cargo-dist/tests/snapshots/install_path_cargo_home.snap +++ b/cargo-dist/tests/snapshots/install_path_cargo_home.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$CARGO_HOME/bin (\$HOME/.cargo/bin) -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -290,7 +290,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -305,8 +307,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -332,14 +356,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" 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 0e202d6ab..65085445c 100644 --- a/cargo-dist/tests/snapshots/install_path_env_no_subdir.snap +++ b/cargo-dist/tests/snapshots/install_path_env_no_subdir.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$MY_ENV_VAR/ -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -273,7 +273,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -288,8 +290,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -315,14 +339,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" diff --git a/cargo-dist/tests/snapshots/install_path_env_subdir.snap b/cargo-dist/tests/snapshots/install_path_env_subdir.snap index 396eb5e27..6b6c1b91c 100644 --- a/cargo-dist/tests/snapshots/install_path_env_subdir.snap +++ b/cargo-dist/tests/snapshots/install_path_env_subdir.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$MY_ENV_VAR/bin -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -273,7 +273,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -288,8 +290,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -315,14 +339,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" 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 016e04107..cebb0f61d 100644 --- a/cargo-dist/tests/snapshots/install_path_env_subdir_space.snap +++ b/cargo-dist/tests/snapshots/install_path_env_subdir_space.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$MY_ENV_VAR/My Axolotlsay Documents -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -273,7 +273,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -288,8 +290,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -315,14 +339,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" 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 9d640a28c..ef7082967 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 @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$MY_ENV_VAR/My Axolotlsay Documents/bin -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -273,7 +273,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -288,8 +290,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -315,14 +339,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" 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 979d9d985..da5a402a0 100644 --- a/cargo-dist/tests/snapshots/install_path_home_subdir_deeper.snap +++ b/cargo-dist/tests/snapshots/install_path_home_subdir_deeper.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$HOME/.axolotlsay/bins -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -273,7 +273,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -288,8 +290,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -315,14 +339,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" 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 1014a1e74..acab6f00f 100644 --- a/cargo-dist/tests/snapshots/install_path_home_subdir_min.snap +++ b/cargo-dist/tests/snapshots/install_path_home_subdir_min.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$HOME/.axolotlsay -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -273,7 +273,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -288,8 +290,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -315,14 +339,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" 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 1e9ab67dc..0727065c7 100644 --- a/cargo-dist/tests/snapshots/install_path_home_subdir_space.snap +++ b/cargo-dist/tests/snapshots/install_path_home_subdir_space.snap @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$HOME/My Axolotlsay Documents -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -273,7 +273,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -288,8 +290,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -315,14 +339,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" 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 15852afb4..3de2db1a0 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 @@ -45,7 +45,7 @@ This script detects what platform you're on and fetches an appropriate archive f https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1 then unpacks the binaries and installs them to \$HOME/My Axolotlsay Documents/bin -It will then add that dir to PATH by adding the appropriate line to \$HOME/.profile +It will then add that dir to PATH by adding the appropriate line to your shell profiles. USAGE: axolotlsay-installer.sh [OPTIONS] @@ -273,7 +273,9 @@ install() { say "everything's installed!" if [ "0" = "$NO_MODIFY_PATH" ]; then - add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" + add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" fi } @@ -288,8 +290,30 @@ add_install_dir_to_path() { local _install_dir_expr="$1" local _env_script_path="$2" local _env_script_path_expr="$3" + local _rcfiles="$4" + if [ -n "${HOME:-}" ]; then - local _rcfile="$HOME/.profile" + local _target + + # 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" + + if [ -f "$_rcfile" ]; then + _target="$_rcfile" + break + fi + done + + # If we didn't find anything, pick the first entry in the + # list as the default to create and write to + if [ -z "${_target:-}" ]; then + local _rcfile_relative + _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')" + _target="$HOME/$_rcfile_relative" + fi + # `source x` is an alias for `. x`, and the latter is more portable/actually-posix. # This apparently comes up a lot on freebsd. It's easy enough to always add # the more robust line to rcfiles, but when telling the user to apply the change @@ -315,14 +339,14 @@ add_install_dir_to_path() { # (on error we want to create the file, which >> conveniently does) # # We search for both kinds of line here just to do the right thing in more cases. - if ! grep -F "$_robust_line" "$_rcfile" > /dev/null 2>/dev/null && \ - ! grep -F "$_pretty_line" "$_rcfile" > /dev/null 2>/dev/null + if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \ + ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null then # If the script now exists, add the line to source it to the rcfile # (This will also create the rcfile if it doesn't exist) if [ -f "$_env_script_path" ]; then - say_verbose "adding $_robust_line to $_rcfile" - ensure echo "$_robust_line" >> "$_rcfile" + say_verbose "adding $_robust_line to $_target" + ensure echo "$_robust_line" >> "$_target" say "" say "To add $_install_dir_expr to your PATH, either restart your shell or run:" say "" From dabcf3e2ea62d8a942af3d418525e01b857c62a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Misty=20De=20M=C3=A9o?= Date: Mon, 4 Dec 2023 11:58:28 -0800 Subject: [PATCH 2/3] tests: test for extra rcfiles --- cargo-dist/tests/gallery/dist.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cargo-dist/tests/gallery/dist.rs b/cargo-dist/tests/gallery/dist.rs index 4137833de..da61f9baa 100644 --- a/cargo-dist/tests/gallery/dist.rs +++ b/cargo-dist/tests/gallery/dist.rs @@ -376,7 +376,11 @@ impl DistResult { // we could theoretically look at the above output and parse out the `source` line... // Check that the script wrote files where we expected - let rcfile = tempdir.join(".profile"); + let rcfiles = &[ + tempdir.join(".profile"), + tempdir.join(".bash_profile"), + tempdir.join(".zshrc"), + ]; let expected_bin_dir = Utf8PathBuf::from(expected_bin_dir); let bin_dir = tempdir.join(&expected_bin_dir); let env_dir = if expected_bin_dir @@ -390,7 +394,9 @@ impl DistResult { let env_script = env_dir.join("env"); assert!(bin_dir.exists(), "bin dir wasn't created"); - assert!(rcfile.exists(), ".profile wasn't created"); + for rcfile in rcfiles { + assert!(rcfile.exists(), "{} wasn't created", rcfile); + } assert!(env_script.exists(), "env script wasn't created"); // Check that all the binaries work @@ -411,9 +417,10 @@ impl DistResult { let test_script_text = format!( r#"#!/bin/sh - . {rcfile} + . {} which {bin_name} - "# + "#, + rcfiles.first().expect("rcfiles was empty?!") ); LocalAsset::write_new(&test_script_text, &test_script_path)?; std::fs::set_permissions(&test_script_path, std::fs::Permissions::from_mode(0o755)) From 90ca70d6fd9b34fb4e4f0d33255d5f332e3e6585 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 3/3] feat: support ZDOTDIR in installer --- .../templates/installer/installer.sh.j2 | 29 +++++++++++++++++-- cargo-dist/tests/gallery/dist.rs | 1 + .../tests/snapshots/akaikatana_basic.snap | 29 +++++++++++++++++-- .../tests/snapshots/akaikatana_musl.snap | 29 +++++++++++++++++-- .../akaikatana_repo_with_dot_git.snap | 29 +++++++++++++++++-- .../tests/snapshots/axolotlsay_abyss.snap | 29 +++++++++++++++++-- .../snapshots/axolotlsay_abyss_only.snap | 29 +++++++++++++++++-- .../tests/snapshots/axolotlsay_basic.snap | 29 +++++++++++++++++-- .../snapshots/axolotlsay_edit_existing.snap | 29 +++++++++++++++++-- .../tests/snapshots/axolotlsay_musl.snap | 29 +++++++++++++++++-- .../snapshots/axolotlsay_musl_no_gnu.snap | 29 +++++++++++++++++-- .../axolotlsay_no_homebrew_publish.snap | 29 +++++++++++++++++-- .../axolotlsay_ssldotcom_windows_sign.snap | 29 +++++++++++++++++-- ...xolotlsay_ssldotcom_windows_sign_prod.snap | 29 +++++++++++++++++-- .../axolotlsay_user_publish_job.snap | 29 +++++++++++++++++-- .../snapshots/install_path_cargo_home.snap | 29 +++++++++++++++++-- .../snapshots/install_path_env_no_subdir.snap | 29 +++++++++++++++++-- .../snapshots/install_path_env_subdir.snap | 29 +++++++++++++++++-- .../install_path_env_subdir_space.snap | 29 +++++++++++++++++-- .../install_path_env_subdir_space_deeper.snap | 29 +++++++++++++++++-- .../install_path_home_subdir_deeper.snap | 29 +++++++++++++++++-- .../install_path_home_subdir_min.snap | 29 +++++++++++++++++-- .../install_path_home_subdir_space.snap | 29 +++++++++++++++++-- ...install_path_home_subdir_space_deeper.snap | 29 +++++++++++++++++-- 24 files changed, 622 insertions(+), 46 deletions(-) diff --git a/cargo-dist/templates/installer/installer.sh.j2 b/cargo-dist/templates/installer/installer.sh.j2 index 39834acf0..ad2c344ba 100644 --- a/cargo-dist/templates/installer/installer.sh.j2 +++ b/cargo-dist/templates/installer/installer.sh.j2 @@ -313,6 +313,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -328,11 +350,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 +369,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..6307dd2c1 100644 --- a/cargo-dist/tests/snapshots/akaikatana_basic.snap +++ b/cargo-dist/tests/snapshots/akaikatana_basic.snap @@ -296,6 +296,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +333,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 +352,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..03e3a2196 100644 --- a/cargo-dist/tests/snapshots/akaikatana_musl.snap +++ b/cargo-dist/tests/snapshots/akaikatana_musl.snap @@ -306,6 +306,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -321,11 +343,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 +362,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..6307dd2c1 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,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +333,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 +352,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..ebd6b22fc 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_abyss.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_abyss.snap @@ -296,6 +296,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +333,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 +352,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..f288bbfbf 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap @@ -296,6 +296,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +333,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 +352,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..b076d6406 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_basic.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_basic.snap @@ -296,6 +296,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +333,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 +352,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..77021a50b 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap @@ -296,6 +296,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +333,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 +352,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..71ec86e8f 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_musl.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_musl.snap @@ -306,6 +306,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -321,11 +343,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 +362,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..a919a816b 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap @@ -306,6 +306,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -321,11 +343,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 +362,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..e08722a5f 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap @@ -296,6 +296,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +333,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 +352,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..0323b1b99 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap @@ -296,6 +296,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +333,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 +352,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..346f24335 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,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +333,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 +352,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..4d7d62057 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap @@ -296,6 +296,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +333,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 +352,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..8952fa374 100644 --- a/cargo-dist/tests/snapshots/install_path_cargo_home.snap +++ b/cargo-dist/tests/snapshots/install_path_cargo_home.snap @@ -296,6 +296,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -311,11 +333,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 +352,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..6282974af 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,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +316,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 +335,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..d8eadf1de 100644 --- a/cargo-dist/tests/snapshots/install_path_env_subdir.snap +++ b/cargo-dist/tests/snapshots/install_path_env_subdir.snap @@ -279,6 +279,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +316,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 +335,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..045679f1d 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,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +316,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 +335,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..738bd1337 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,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +316,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 +335,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..634a32ad6 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,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +316,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 +335,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..a945f1468 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,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +316,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 +335,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..326e5babf 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,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +316,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 +335,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..9cb5b3bd0 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,28 @@ 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*) + if [ -n "$ZDOTDIR" ]; then + _home="$ZDOTDIR" + else + _home="$HOME" + fi + ;; + *) + _home="$HOME" + ;; + esac + + echo "$_home" +} + add_install_dir_to_path() { # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH # @@ -294,11 +316,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 +335,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.