From 2bcd165a78cd20fb6eea0f1ddb0213da7fddf8a1 Mon Sep 17 00:00:00 2001 From: Zach Day Date: Tue, 14 Mar 2017 03:39:26 -0400 Subject: Add CLI arg for setting working directory Resolves #478. --- src/cli.rs | 11 +++++++++++ src/tty.rs | 5 +++++ 2 files changed, 16 insertions(+) (limited to 'src') 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>, + pub working_dir: Option, } 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(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 { -- cgit v1.2.3