summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorZach Day <zachdayz@gmail.com>2017-03-14 03:39:26 -0400
committerJoe Wilm <joe@jwilm.com>2017-04-18 19:53:31 -0700
commit2bcd165a78cd20fb6eea0f1ddb0213da7fddf8a1 (patch)
tree829ba86e4dd881c43f57415a5c59a86bc9fc5f4f /src
parenta3d00f01b136ce95613bb20db9e05bfe9342185b (diff)
Add CLI arg for setting working directory
Resolves #478.
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs11
-rw-r--r--src/tty.rs5
2 files changed, 16 insertions, 0 deletions
diff --git a/src/cli.rs b/src/cli.rs
index f8f76e59..4a455cf4 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -15,6 +15,7 @@ extern crate log;
use clap::{Arg, App};
use index::{Line, Column};
use config::{Dimensions, Shell};
+use std::path::PathBuf;
const DEFAULT_TITLE: &'static str = "Alacritty";
@@ -26,6 +27,7 @@ pub struct Options {
pub title: String,
pub log_level: log::LogLevelFilter,
pub command: Option<Shell<'static>>,
+ pub working_dir: Option<PathBuf>,
}
impl Default for Options {
@@ -37,6 +39,7 @@ impl Default for Options {
title: DEFAULT_TITLE.to_owned(),
log_level: log::LogLevelFilter::Warn,
command: None,
+ working_dir: None,
}
}
}
@@ -75,6 +78,10 @@ impl Options {
.multiple(true)
.conflicts_with("q")
.help("Increases the level of verbosity (the max level is -vvv)"))
+ .arg(Arg::with_name("working-directory")
+ .long("working-directory")
+ .takes_value(true)
+ .help("Start the shell in the specified working directory"))
.arg(Arg::with_name("command")
.short("e")
.multiple(true)
@@ -117,6 +124,10 @@ impl Options {
3 | _ => options.log_level = log::LogLevelFilter::Trace
}
+ if let Some(dir) = matches.value_of("working-directory") {
+ options.working_dir = Some(PathBuf::from(dir.to_string()));
+ }
+
if let Some(mut args) = matches.values_of("command") {
// The following unwrap is guaranteed to succeed.
// If 'command' exists it must also have a first item since
diff --git a/src/tty.rs b/src/tty.rs
index eb0ba590..9f8a4764 100644
--- a/src/tty.rs
+++ b/src/tty.rs
@@ -235,6 +235,11 @@ pub fn new<T: ToWinsize>(config: &Config, options: &Options, size: T) -> Pty {
Ok(())
});
+ // Handle set working directory option
+ if let Some(ref dir) = options.working_dir {
+ builder.current_dir(dir.as_path());
+ }
+
match builder.spawn() {
Ok(child) => {
unsafe {