fix(edit): treat cwd properly (#1904)
This commit is contained in:
parent
4905ae65b8
commit
9ebc9b74ee
4 changed files with 23 additions and 1 deletions
|
|
@ -46,13 +46,22 @@ fn main() {
|
||||||
direction,
|
direction,
|
||||||
line_number,
|
line_number,
|
||||||
floating,
|
floating,
|
||||||
|
cwd,
|
||||||
})) = opts.command
|
})) = opts.command
|
||||||
{
|
{
|
||||||
|
let mut file = file;
|
||||||
|
let cwd = cwd.or_else(|| std::env::current_dir().ok());
|
||||||
|
if file.is_relative() {
|
||||||
|
if let Some(cwd) = cwd.as_ref() {
|
||||||
|
file = cwd.join(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
let command_cli_action = CliAction::Edit {
|
let command_cli_action = CliAction::Edit {
|
||||||
file,
|
file,
|
||||||
direction,
|
direction,
|
||||||
line_number,
|
line_number,
|
||||||
floating,
|
floating,
|
||||||
|
cwd,
|
||||||
};
|
};
|
||||||
commands::send_action_to_session(command_cli_action, opts.session);
|
commands::send_action_to_session(command_cli_action, opts.session);
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
|
|
|
||||||
|
|
@ -1943,6 +1943,7 @@ pub fn send_cli_edit_action_with_default_parameters() {
|
||||||
direction: None,
|
direction: None,
|
||||||
line_number: None,
|
line_number: None,
|
||||||
floating: false,
|
floating: false,
|
||||||
|
cwd: None,
|
||||||
};
|
};
|
||||||
send_cli_action_to_server(
|
send_cli_action_to_server(
|
||||||
&session_metadata,
|
&session_metadata,
|
||||||
|
|
@ -1980,6 +1981,7 @@ pub fn send_cli_edit_action_with_line_number() {
|
||||||
direction: None,
|
direction: None,
|
||||||
line_number: Some(100),
|
line_number: Some(100),
|
||||||
floating: false,
|
floating: false,
|
||||||
|
cwd: None,
|
||||||
};
|
};
|
||||||
send_cli_action_to_server(
|
send_cli_action_to_server(
|
||||||
&session_metadata,
|
&session_metadata,
|
||||||
|
|
@ -2017,6 +2019,7 @@ pub fn send_cli_edit_action_with_split_direction() {
|
||||||
direction: Some(Direction::Down),
|
direction: Some(Direction::Down),
|
||||||
line_number: None,
|
line_number: None,
|
||||||
floating: false,
|
floating: false,
|
||||||
|
cwd: None,
|
||||||
};
|
};
|
||||||
send_cli_action_to_server(
|
send_cli_action_to_server(
|
||||||
&session_metadata,
|
&session_metadata,
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,10 @@ pub enum Sessions {
|
||||||
/// Open the new pane in floating mode
|
/// Open the new pane in floating mode
|
||||||
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
|
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
|
||||||
floating: bool,
|
floating: bool,
|
||||||
|
|
||||||
|
/// Change the working directory of the editor
|
||||||
|
#[clap(long, value_parser)]
|
||||||
|
cwd: Option<PathBuf>,
|
||||||
},
|
},
|
||||||
ConvertConfig {
|
ConvertConfig {
|
||||||
old_config_file: PathBuf,
|
old_config_file: PathBuf,
|
||||||
|
|
@ -282,6 +286,10 @@ pub enum CliAction {
|
||||||
/// Open the new pane in floating mode
|
/// Open the new pane in floating mode
|
||||||
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
|
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
|
||||||
floating: bool,
|
floating: bool,
|
||||||
|
|
||||||
|
/// Change the working directory of the editor
|
||||||
|
#[clap(long, value_parser)]
|
||||||
|
cwd: Option<PathBuf>,
|
||||||
},
|
},
|
||||||
/// Switch input mode of all connected clients [locked|pane|tab|resize|move|search|session]
|
/// Switch input mode of all connected clients [locked|pane|tab|resize|move|search|session]
|
||||||
SwitchMode { input_mode: InputMode },
|
SwitchMode { input_mode: InputMode },
|
||||||
|
|
|
||||||
|
|
@ -301,10 +301,12 @@ impl Action {
|
||||||
file,
|
file,
|
||||||
line_number,
|
line_number,
|
||||||
floating,
|
floating,
|
||||||
|
cwd,
|
||||||
} => {
|
} => {
|
||||||
let mut file = file;
|
let mut file = file;
|
||||||
|
let cwd = cwd.or_else(|| std::env::current_dir().ok());
|
||||||
if file.is_relative() {
|
if file.is_relative() {
|
||||||
if let Some(cwd) = std::env::current_dir().ok() {
|
if let Some(cwd) = cwd {
|
||||||
file = cwd.join(file);
|
file = cwd.join(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue