diff --git a/src/cli/commands/client.rs b/src/cli/commands/client.rs index ffdd3b1..7663ced 100644 --- a/src/cli/commands/client.rs +++ b/src/cli/commands/client.rs @@ -134,6 +134,10 @@ pub enum ClientSubcommand { #[clap(flatten)] network: NetworkConfig, + /// Alternative current directory for the remote process + #[clap(long)] + current_dir: Option, + /// If provided, will run LSP in a pty #[clap(long)] pty: bool, @@ -206,6 +210,10 @@ pub enum ClientSubcommand { #[clap(flatten)] network: NetworkConfig, + /// Alternative current directory for the remote process + #[clap(long)] + current_dir: Option, + /// Environment variables to provide to the shell #[clap(long, default_value_t)] environment: Environment, @@ -556,6 +564,7 @@ impl ClientSubcommand { Self::Lsp { connection, network, + current_dir, pty, cmd, .. @@ -581,7 +590,7 @@ impl ClientSubcommand { debug!("Spawning LSP server (pty = {}): {}", pty, cmd); Lsp::new(channel.into_client().into_channel()) - .spawn(cmd, pty) + .spawn(cmd, current_dir, pty) .await?; } Self::Repl { @@ -852,6 +861,7 @@ impl ClientSubcommand { Self::Shell { connection, network, + current_dir, environment, cmd, .. @@ -881,7 +891,7 @@ impl ClientSubcommand { cmd.as_deref().unwrap_or(r"$SHELL") ); Shell::new(channel.into_client().into_channel()) - .spawn(cmd, environment) + .spawn(cmd, environment, current_dir) .await?; } } diff --git a/src/cli/commands/client/lsp.rs b/src/cli/commands/client/lsp.rs index 4cbe163..e877708 100644 --- a/src/cli/commands/client/lsp.rs +++ b/src/cli/commands/client/lsp.rs @@ -1,6 +1,7 @@ use super::{link::RemoteProcessLink, CliError, CliResult}; use anyhow::Context; use distant_core::{data::PtySize, DistantChannel, RemoteLspCommand}; +use std::path::PathBuf; use terminal_size::{terminal_size, Height, Width}; #[derive(Clone)] @@ -11,7 +12,12 @@ impl Lsp { Self(channel) } - pub async fn spawn(self, cmd: impl Into, pty: bool) -> CliResult { + pub async fn spawn( + self, + cmd: impl Into, + current_dir: Option, + pty: bool, + ) -> CliResult { let cmd = cmd.into(); let mut proc = RemoteLspCommand::new() .pty(if pty { @@ -21,6 +27,7 @@ impl Lsp { } else { None }) + .current_dir(current_dir) .spawn(self.0, &cmd) .await .with_context(|| format!("Failed to spawn {cmd}"))?; diff --git a/src/cli/commands/client/shell.rs b/src/cli/commands/client/shell.rs index 247fa72..f76983d 100644 --- a/src/cli/commands/client/shell.rs +++ b/src/cli/commands/client/shell.rs @@ -5,6 +5,7 @@ use distant_core::{ DistantChannel, DistantChannelExt, RemoteCommand, }; use log::*; +use std::path::PathBuf; use std::time::Duration; use terminal_size::{terminal_size, Height, Width}; use termwiz::{ @@ -25,6 +26,7 @@ impl Shell { mut self, cmd: impl Into>, mut environment: Environment, + current_dir: Option, ) -> CliResult { // Automatically add TERM=xterm-256color if not specified if !environment.contains_key("TERM") { @@ -59,6 +61,7 @@ impl Shell { terminal_size() .map(|(Width(cols), Height(rows))| PtySize::from_rows_and_cols(rows, cols)), ) + .current_dir(current_dir) .spawn(self.0, &cmd) .await .with_context(|| format!("Failed to spawn {cmd}"))?;