Browse Source

Escape quotes on PS1

master
Hamcha 12 months ago
parent
commit
4269888e8c
Signed by: Hamcha GPG Key ID: 41467804B19A3315
  1. 2
      Cargo.lock
  2. 2
      Cargo.toml
  3. 6
      src/main.rs

2
Cargo.lock

@ -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)",

2
Cargo.toml

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

6
src/main.rs

@ -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),

Loading…
Cancel
Save