Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
**/*.rs.bk
Cargo.lock
.DS_Store
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ env_perm::check_or_set("DUMMY", 1).expect("Failed to find or set DUMMY");
// Append $HOME/some/cool/bin to $PATH
// export PATH= "$HOME/some/cool/bin:$PATH"
env_perm::append("PATH", "$HOME/some/cool/bin").expect("Couldn't find PATH");
// Append $HOME/some/cooler/bin to the end of the path
// export PATH="$PATH:$HOME/some/cooler/bin"
env_perm::append_to_end("PATH", "$HOME/some/cooler/bin").expect("Couldn't find PATH");
// Sets a variable without checking if it exists.
// Note you need to use a raw string literal to include ""
// export DUMMY="/something"
Expand Down
3 changes: 3 additions & 0 deletions examples/set_dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ fn main() {
// Append $HOME/some/cool/bin to $PATH
// export PATH= "$HOME/some/cool/bin:$PATH"
env_perm::append("PATH", "$HOME/some/cool/bin").expect("Couldn't find PATH");
// Append $HOME/some/cooler/bin to the end of the path
// export PATH= "$PATH:$HOME/some/cooler/bin"
env_perm::append_to_end("PATH", "$HOME/some/cooler/bin").expect("Couldn't find PATH");
// Sets a variable without checking if it exists.
// Note you need to use a raw string literal to include ""
// export DUMMY="/something"
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
//! // Append $HOME/some/cool/bin to $PATH
//! // export PATH= "$HOME/some/cool/bin:$PATH"
//! env_perm::append("PATH", "$HOME/some/cool/bin").expect("Couldn't find PATH");
//! // Append $HOME/some/cooler/bin to the front of the path
//! // export PATH="$PATH:$HOME/some/cooler/bin"
//! env_perm::append_to_end("PATH", "$HOME/some/cooler/bin").expect("Couldn't find PATH");
//! // Sets a variable without checking if it exists.
//! // Note you need to use a raw string literal to include ""
//! // export DUMMY="/something"
Expand Down Expand Up @@ -42,6 +45,13 @@ pub fn append<T: fmt::Display>(var: T, value: T) -> io::Result<()> {
profile.flush()
}

/// Appends a value to an environment variable at either the front or end
pub fn append_to_end<T: fmt::Display>(var: T, value: T) -> io::Result<()> {
let mut profile = get_profile()?;
writeln!(profile, "\nexport {}=\"${}:{}\"", var, var, value)?;
profile.flush()
}

/// Sets an environment variable without checking
/// if it exists.
/// If it does you will end up with two
Expand Down