Skip to content

Commit

Permalink
rig rstudio keep working dir on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed Aug 28, 2023
1 parent 6282eee commit 7841fe6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
22 changes: 18 additions & 4 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ macro_rules! strvec {
});
}

macro_rules! osvec {
// match a list of expressions separated by comma:
($($str:expr),*) => ({
// create a Vec with this list of expressions,
// calling String::from on each:
vec![$(OsString::from($str),)*] as Vec<OsString>
});
}

pub fn sc_add(args: &ArgMatches) -> Result<(), Box<dyn Error>> {
escalate("adding new R versions")?;

Expand Down Expand Up @@ -810,9 +819,14 @@ pub fn sc_system_update_rtools40() -> Result<(), Box<dyn Error>> {

pub fn sc_rstudio_(version: Option<&str>, project: Option<&str>, arg: Option<&OsStr>)
-> Result<(), Box<dyn Error>> {

let cwd = std::env::current_dir();
let (cmd, mut args) = match project {
Some(p) => ("xdg-open", vec![p]),
None => ("rstudio", vec![]),
Some(p) => ("xdg-open", osvec![p]),
None => match cwd {
Ok(x) => ("rstudio", osvec![x]),
Err(_) => ("rstudio", osvec![])
}
};

let mut envname = "dummy";
Expand All @@ -824,10 +838,10 @@ pub fn sc_rstudio_(version: Option<&str>, project: Option<&str>, arg: Option<&Os
};

if let Some(arg) = arg {
args.push(arg.to_str().unwrap_or("."));
args.push(arg.into());
}

info!("Running {} {}", cmd, args.join(" "));
info!("Running {} {:?}", cmd, args.join(&os(" ")));

Command::new(cmd)
.args(args)
Expand Down
1 change: 0 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use simplelog::*;
#[cfg(any(target_os = "macos", target_os = "linux"))]
use crate::rversion::*;

#[cfg(any(target_os = "macos", target_os = "windows"))]
pub fn os(x: &str) -> OsString {
let mut ostr = OsString::new();
ostr.push(x);
Expand Down

0 comments on commit 7841fe6

Please sign in to comment.