Skip to content

Instantly share code, notes, and snippets.

@vizee
Last active April 27, 2021 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vizee/2780f6d8816ee172ee73d92df835d2bf to your computer and use it in GitHub Desktop.
Save vizee/2780f6d8816ee172ee73d92df835d2bf to your computer and use it in GitHub Desktop.
terminal bootstrap
// rustc -O bootstrap.rs
use std::env;
use std::process::Command;
#[cfg(target_os = "windows")]
fn terminal() -> Command {
Command::new("msys2.exe")
.env("CHERE_INVOKING", "1")
}
#[cfg(target_os = "linux")]
fn terminal() -> Command {
Command::new("/home/vizee/.cargo/bin/alacritty")
}
fn main() {
let wd = env::current_dir().unwrap();
let root = env::args()
.skip(1)
.next()
.map(|s| std::path::PathBuf::from(s))
.unwrap_or(wd.clone());
terminal()
.current_dir(if wd.starts_with(&root) { wd } else { root })
.spawn()
.unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment