mirror of
https://github.com/alacritty/alacritty.git
synced 2025-02-10 15:46:10 -05:00
Implement argument passing in config
This commit implements the following syntax in the config file: ```yaml shell: program: /bin/bash args: - --login - --norc ```
This commit is contained in:
parent
1dca5617e2
commit
04c5ad372a
2 changed files with 42 additions and 13 deletions
|
@ -12,6 +12,7 @@ use std::str::FromStr;
|
|||
use std::sync::mpsc;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::fs::File;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use ::Rgb;
|
||||
use font::Size;
|
||||
|
@ -166,6 +167,31 @@ impl IndexMut<usize> for ColorList {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Shell<'a> {
|
||||
program: Cow<'a, str>,
|
||||
|
||||
#[serde(default)]
|
||||
args: Vec<String>,
|
||||
}
|
||||
|
||||
impl<'a> Shell<'a> {
|
||||
pub fn new(program: &'a str) -> Shell<'a> {
|
||||
Shell {
|
||||
program: Cow::from(program),
|
||||
args: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn program(&self) -> &str {
|
||||
&*self.program
|
||||
}
|
||||
|
||||
pub fn args(&self) -> &[String] {
|
||||
self.args.as_slice()
|
||||
}
|
||||
}
|
||||
|
||||
/// Top-level config type
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Config {
|
||||
|
@ -197,7 +223,8 @@ pub struct Config {
|
|||
mouse_bindings: Vec<MouseBinding>,
|
||||
|
||||
/// Path to a shell program to run on startup
|
||||
shell: Option<String>,
|
||||
#[serde(default)]
|
||||
shell: Option<Shell<'static>>,
|
||||
|
||||
/// Path where config was loaded from
|
||||
config_path: Option<PathBuf>,
|
||||
|
@ -902,10 +929,8 @@ impl Config {
|
|||
.map(|p| p.as_path())
|
||||
}
|
||||
|
||||
pub fn shell(&self) -> Option<&str> {
|
||||
self.shell
|
||||
.as_ref()
|
||||
.map(String::as_str)
|
||||
pub fn shell(&self) -> Option<&Shell> {
|
||||
self.shell.as_ref()
|
||||
}
|
||||
|
||||
fn load_from<P: Into<PathBuf>>(path: P) -> Result<Config> {
|
||||
|
|
20
src/tty.rs
20
src/tty.rs
|
@ -19,13 +19,13 @@ use std::fs::File;
|
|||
use std::os::unix::io::FromRawFd;
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::ptr;
|
||||
use std::process;
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
use libc::{self, winsize, c_int, pid_t, WNOHANG, WIFEXITED, WEXITSTATUS, SIGCHLD, TIOCSCTTY};
|
||||
|
||||
use term::SizeInfo;
|
||||
use display::OnResize;
|
||||
use config::Config;
|
||||
use config::{Config, Shell};
|
||||
|
||||
/// Process ID of child process
|
||||
///
|
||||
|
@ -186,19 +186,23 @@ pub fn new<T: ToWinsize>(config: &Config, size: T) -> Pty {
|
|||
|
||||
let (master, slave) = openpty(win.ws_row as _, win.ws_col as _);
|
||||
|
||||
let shell = config.shell().unwrap_or(pw.shell);
|
||||
let default_shell = Shell::new(pw.shell);
|
||||
let shell = config.shell().unwrap_or(&default_shell);
|
||||
|
||||
let mut builder = process::Command::new(shell);
|
||||
let mut builder = Command::new(shell.program());
|
||||
for arg in shell.args() {
|
||||
builder.arg(arg);
|
||||
}
|
||||
|
||||
// Setup child stdin/stdout/stderr as slave fd of pty
|
||||
builder.stdin(unsafe { process::Stdio::from_raw_fd(slave) });
|
||||
builder.stderr(unsafe { process::Stdio::from_raw_fd(slave) });
|
||||
builder.stdout(unsafe { process::Stdio::from_raw_fd(slave) });
|
||||
builder.stdin(unsafe { Stdio::from_raw_fd(slave) });
|
||||
builder.stderr(unsafe { Stdio::from_raw_fd(slave) });
|
||||
builder.stdout(unsafe { Stdio::from_raw_fd(slave) });
|
||||
|
||||
// Setup environment
|
||||
builder.env("LOGNAME", pw.name);
|
||||
builder.env("USER", pw.name);
|
||||
builder.env("SHELL", shell);
|
||||
builder.env("SHELL", shell.program());
|
||||
builder.env("HOME", pw.dir);
|
||||
builder.env("TERM", "xterm-256color"); // sigh
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue