Skip to content

Commit

Permalink
fix: don't modify dotfiles when install_dir in PATH
Browse files Browse the repository at this point in the history
This is a proof-of-concept for astral-sh/uv#5576 and #830: When the install dir is already in PATH, don't modify the user's dotfile.

For my use case, i set `export PATH="$HOME/.cargo/bin/:$PATH"` manually and don't want to source arbitrary other files; I've had bad experiences with tools that would make intrusive changes to my shell by souring their slow script on every bash startup, and a single file configuration is much easier to debug.

Caveat: I have no idea how portable this code is.
  • Loading branch information
konstin authored and mistydemeo committed Aug 7, 2024
1 parent 12cfef0 commit 6505eca
Show file tree
Hide file tree
Showing 44 changed files with 270 additions and 23 deletions.
6 changes: 6 additions & 0 deletions cargo-dist/templates/installer/installer.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,12 @@ install() {

say "{{ install_success_msg }}"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/akaikatana_basic.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: cargo-dist/tests/gallery/dist/snapshot.rs
assertion_line: 92
expression: self.payload
---
================ akaikatana-repack-installer.sh ================
Expand Down Expand Up @@ -486,6 +485,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/akaikatana_musl.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: cargo-dist/tests/gallery/dist/snapshot.rs
assertion_line: 92
expression: self.payload
---
================ akaikatana-repack-installer.sh ================
Expand Down Expand Up @@ -508,6 +507,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: cargo-dist/tests/gallery/dist/snapshot.rs
assertion_line: 92
expression: self.payload
---
================ akaikatana-repack-installer.sh ================
Expand Down Expand Up @@ -498,6 +497,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/akaikatana_two_bin_aliases.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: cargo-dist/tests/gallery/dist/snapshot.rs
assertion_line: 92
expression: self.payload
---
================ akaikatana-repack-installer.sh ================
Expand Down Expand Up @@ -510,6 +509,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/akaikatana_updaters.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: cargo-dist/tests/gallery/dist/snapshot.rs
assertion_line: 92
expression: self.payload
---
================ akaikatana-repack-installer.sh ================
Expand Down Expand Up @@ -486,6 +485,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
6 changes: 6 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_abyss.snap
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
6 changes: 6 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
6 changes: 6 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_alias.snap
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
6 changes: 6 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_basic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ install() {

say ">o_o< everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
6 changes: 6 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_basic_lies.snap
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
6 changes: 6 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_build_setup_steps.snap
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ install() {

say ">o_o< everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/axolotlsay_checksum_blake2b.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: cargo-dist/tests/gallery/dist/snapshot.rs
assertion_line: 92
expression: self.payload
---
================ axolotlsay-installer.sh ================
Expand Down Expand Up @@ -486,6 +485,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/axolotlsay_checksum_blake2s.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: cargo-dist/tests/gallery/dist/snapshot.rs
assertion_line: 92
expression: self.payload
---
================ axolotlsay-installer.sh ================
Expand Down Expand Up @@ -486,6 +485,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/axolotlsay_checksum_sha3_256.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: cargo-dist/tests/gallery/dist/snapshot.rs
assertion_line: 92
expression: self.payload
---
================ axolotlsay-installer.sh ================
Expand Down Expand Up @@ -486,6 +485,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/axolotlsay_checksum_sha3_512.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: cargo-dist/tests/gallery/dist/snapshot.rs
assertion_line: 92
expression: self.payload
---
================ axolotlsay-installer.sh ================
Expand Down Expand Up @@ -486,6 +485,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
6 changes: 6 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: cargo-dist/tests/gallery/dist/snapshot.rs
assertion_line: 106
expression: self.payload
---
================ axolotlsay-js-installer.sh ================
Expand Down Expand Up @@ -486,6 +485,12 @@ install() {

say ">o_o< everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down Expand Up @@ -2045,6 +2050,12 @@ install() {

say ">o_o< everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
6 changes: 6 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_homebrew_packages.snap
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
6 changes: 6 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_musl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
6 changes: 6 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ install() {

say "everything's installed!"

# Avoid modifying the users PATH if they are managing their PATH manually
case :$PATH:
in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
*) ;;
esac

if [ "0" = "$NO_MODIFY_PATH" ]; then
add_install_dir_to_ci_path "$_install_dir"
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
Expand Down
Loading

0 comments on commit 6505eca

Please sign in to comment.