diff options
author | Niklas Claesson <nicke.claesson@gmail.com> | 2017-01-23 20:10:26 +0100 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2017-01-25 08:50:28 -0800 |
commit | 04c5ad372a90ed26bbe6f79e723aba7d31329fc9 (patch) | |
tree | c3af39774b32a56e3206ffe6b22560181cf8ebfe /src | |
parent | 1dca5617e2c308b3c2f86d6cfa9d530d8d178885 (diff) | |
download | alacritty-04c5ad372a90ed26bbe6f79e723aba7d31329fc9.tar.gz alacritty-04c5ad372a90ed26bbe6f79e723aba7d31329fc9.zip |
Implement argument passing in config
This commit implements the following syntax in the config file:
```yaml
shell:
program: /bin/bash
args:
- --login
- --norc
```
Diffstat (limited to 'src')
-rw-r--r-- | src/config.rs | 35 | ||||
-rw-r--r-- | src/tty.rs | 20 |
2 files changed, 42 insertions, 13 deletions
diff --git a/src/config.rs b/src/config.rs index 0e32e42c..f93406db 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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> { @@ -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 |