Last active
April 27, 2021 05:59
-
-
Save vizee/2780f6d8816ee172ee73d92df835d2bf to your computer and use it in GitHub Desktop.
terminal bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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