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]] [[package]]
name = "osenv" name = "osenv"
version = "0.1.0" version = "1.0.0"
dependencies = [ dependencies = [
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "isatty 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",

View file

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

View file

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