1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-22 22:42:48 +03:00

lookup the $SHELL for the user rather than assume zsh

This commit is contained in:
Wez Furlong 2018-02-06 22:48:28 -08:00
parent a78efced1c
commit 401530a899
2 changed files with 23 additions and 2 deletions

View File

@ -45,7 +45,7 @@ These are in the done/doing soon category:
- [ ] xterm style selection of text with mouse
- [ ] Configuration file to specify fonts and colors
- [ ] Render underline, italic, bold, strikethrough
- [ ] Command line argument parsing / launching of user shell (currently runs only `zsh`!)
- [ ] Command line argument parsing instead of launching user shell
There's a good number of terminal escape sequences that are not yet implemented
and that will get fleshed out as the applications I use uncover them.

View File

@ -20,8 +20,11 @@ extern crate xcb_util;
use mio::{Events, Poll, PollOpt, Ready, Token};
use mio::unix::EventedFd;
use std::env;
use std::ffi::CStr;
use std::os::unix::io::AsRawFd;
use std::process::Command;
use std::str;
use std::time::Duration;
mod xgfx;
@ -34,6 +37,24 @@ mod sigchld;
mod xwin;
use xwin::TerminalWindow;
/// Determine which shell to run.
/// We take the contents of the $SHELL env var first, then
/// fall back to looking it up from the password database.
fn get_shell() -> Result<String, Error> {
env::var("SHELL").or_else(|_| {
let ent = unsafe { libc::getpwuid(libc::getuid()) };
if ent.is_null() {
Ok("/bin/sh".into())
} else {
let shell = unsafe { CStr::from_ptr((*ent).pw_shell) };
shell.to_str().map(str::to_owned).map_err(|e| {
format_err!("failed to resolve shell: {:?}", e)
})
}
})
}
fn run() -> Result<(), Error> {
let poll = Poll::new()?;
let conn = xgfx::Connection::new()?;
@ -63,7 +84,7 @@ fn run() -> Result<(), Error> {
initial_pixel_height,
)?;
let cmd = Command::new("zsh");
let cmd = Command::new(get_shell()?);
let child = slave.spawn_command(cmd)?;
eprintln!("spawned: {:?}", child);