Add --current-dir as option for distant shell and lsp commands

pull/172/head
Chip Senkbeil 1 year ago
parent 55036478a0
commit 40bd20e4ac
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -134,6 +134,10 @@ pub enum ClientSubcommand {
#[clap(flatten)]
network: NetworkConfig,
/// Alternative current directory for the remote process
#[clap(long)]
current_dir: Option<PathBuf>,
/// 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<PathBuf>,
/// 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?;
}
}

@ -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<String>, pty: bool) -> CliResult {
pub async fn spawn(
self,
cmd: impl Into<String>,
current_dir: Option<PathBuf>,
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}"))?;

@ -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<Option<String>>,
mut environment: Environment,
current_dir: Option<PathBuf>,
) -> 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}"))?;

Loading…
Cancel
Save