Add CLI arg for setting working directory

Resolves #478.
This commit is contained in:
Zach Day authored and Joe Wilm committed 2017-04-18 19:53:31 -07:00
1 parent a3d00f01b1
commit 2bcd165a78
2 files changed
+16

No files matched your search

+11
View File
@@ -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
+5
View File
@@ -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 {