aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorNiklas Claesson <nicke.claesson@gmail.com>2017-01-23 20:10:26 +0100
committerJoe Wilm <jwilm@users.noreply.github.com>2017-01-25 08:50:28 -0800
commit04c5ad372a90ed26bbe6f79e723aba7d31329fc9 (patch)
treec3af39774b32a56e3206ffe6b22560181cf8ebfe /src/config.rs
parent1dca5617e2c308b3c2f86d6cfa9d530d8d178885 (diff)
downloadalacritty-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/config.rs')
-rw-r--r--src/config.rs35
1 files changed, 30 insertions, 5 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> {