Escape quotes on PS1

This commit is contained in:
Hamcha 2020-10-02 15:47:40 +02:00
parent 3658941098
commit 4269888e8c
Signed by: Hamcha
GPG Key ID: 41467804B19A3315
3 changed files with 7 additions and 3 deletions

2
Cargo.lock generated
View File

@ -68,7 +68,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "osenv"
version = "0.1.0"
version = "1.0.0"
dependencies = [
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"isatty 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -1,6 +1,6 @@
[package]
name = "osenv"
version = "0.1.0"
version = "1.0.0"
authors = ["Hamcha <hamcha@crunchy.rocks>"]
edition = "2018"

View File

@ -30,6 +30,10 @@ fn get_file(cmd: &ArgMatches) -> Option<PathBuf> {
Some(Path::new(dir).join(filename))
}
fn escape(raw: &str) -> String {
raw.replace("\"", "`\"")
}
fn main() -> std::io::Result<()> {
#[cfg(target_os = "macos")]
static OS_DEFAULT_SHELL: &str = "sh";
@ -116,7 +120,7 @@ fn main() -> std::io::Result<()> {
println!(
"$env:{} = \"{}\"; ",
envline.get(..idx.unwrap()).unwrap(),
envline.get(idx.unwrap() + 1..).unwrap()
escape(envline.get(idx.unwrap() + 1..).unwrap())
)
}
"sh" => println!("export {}", envline),