-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support adding to PATH on Unix systems (posix, bash, and zsh) (#16)
* Support adding to PATH on Unix systems (posix, bash, and zsh) * UI tests, plus preserve HOME variable on unix * Clean up fallback code * Remove test breakpoint (oops)
- Loading branch information
Showing
19 changed files
with
406 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/target | ||
*.snap.new |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
pub fn home_dir() -> Option<PathBuf> { | ||
if let Ok(home) = env::var("AFTMAN_HOME") { | ||
return Some(PathBuf::from(home)); | ||
} | ||
|
||
dirs::home_dir() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
|
||
# This script adds Aftman to the user's PATH and is run via the user's | ||
# shell-specific profile. | ||
# | ||
# This is adapted from Rustup: | ||
# https://github.com/rust-lang/rustup/blob/feec94b6e0203cb6ad023b1e2c953d058e5c3acd/src/cli/self_update/env.sh | ||
|
||
case ":${PATH}:" in | ||
*:"{our_bin_dir}":*) | ||
;; | ||
|
||
*) | ||
export PATH="{our_bin_dir}:$PATH" | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,40 @@ | ||
#[cfg(target_os = "windows")] | ||
use std::env; | ||
|
||
use crate::home::Home; | ||
|
||
mod unix; | ||
|
||
#[cfg(windows)] | ||
mod windows; | ||
|
||
#[cfg(target_os = "windows")] | ||
pub use windows::add; | ||
#[allow(unreachable_code)] | ||
pub fn init(home: &Home) -> anyhow::Result<()> { | ||
// Users can define this environment variable to force Aftman to interact | ||
// with the user's PATH like a Unix machine. This is helpful for running | ||
// tests on Windows. | ||
if cfg!(unix) || env::var("AFTMAN_PATH_UNIX").is_ok() { | ||
return unix::init(home); | ||
} | ||
|
||
#[cfg(windows)] | ||
{ | ||
return windows::init(home); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[allow(unreachable_code)] | ||
pub fn add(home: &Home) -> anyhow::Result<bool> { | ||
if cfg!(unix) || env::var("AFTMAN_PATH_UNIX").is_ok() { | ||
return unix::add(home); | ||
} | ||
|
||
#[cfg(windows)] | ||
{ | ||
return windows::add(home); | ||
} | ||
|
||
#[cfg(not(target_os = "windows"))] | ||
pub fn add(_path: &std::path::Path) -> anyhow::Result<bool> { | ||
log::debug!("Not adding value to path because this platform is not supported."); | ||
Ok(false) | ||
} |
Oops, something went wrong.