Merge pull request 'Take default shell from config and `$SHELL`' (#2) from lilithium-hydride/piss:main into main

Reviewed-on: #2
This commit is contained in:
mars 2022-10-09 03:01:58 +00:00
commit f113ee79bf
2 changed files with 20 additions and 3 deletions

View File

@ -48,12 +48,18 @@ pub struct FontConfig {
pub bold: PathBuf,
}
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct SystemConfig {
pub shell: String,
}
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct Config {
pub cursor: CursorConfig,
pub colors: ColorConfig,
pub draw: DrawConfig,
pub fonts: FontConfig,
pub system: SystemConfig,
}
impl Default for CursorConfig {

View File

@ -42,6 +42,19 @@ impl EventListener for TermListener {
}
}
fn get_login_shell(config: Config) -> String {
if config.system.shell != "" {
config.system.shell
} else {
match std::env::consts::OS {
"linux" | "openbsd" | "netbsd" | "dragonfly" | "solaris" | "macos" =>
std::env::var("SHELL").unwrap_or("/bin/sh".to_string()),
"windows" => r#"C:\Windows\System32\cmd.exe"#.to_string(),
_ => unimplemented!("Unrecognized operating system; cannot get user's shell")
}
}
}
pub struct App {
graphics: Graphics,
graphics_context: GraphicsContext<Window>,
@ -70,9 +83,7 @@ impl App {
let term_config = alacritty_terminal::config::Config {
pty_config: PtyConfig {
shell: Some(alacritty_terminal::config::Program::Just(
"/usr/bin/fish".to_string(),
)),
shell: Some(alacritty_terminal::config::Program::Just(get_login_shell(config))),
working_directory: None,
hold: false,
},