Compare commits

..

No commits in common. "a83cf1013c226416f46b73604f565b2abf2c864d" and "96ac4d792f2724b2b332f1543b7c6b8af07087f4" have entirely different histories.

3 changed files with 12 additions and 30 deletions

View File

@ -7,4 +7,3 @@ edition = "2021"
clap = { version = "4.5.23", features = ["derive"] } clap = { version = "4.5.23", features = ["derive"] }
lazy-regex = "3.3.0" lazy-regex = "3.3.0"
shell-words = "1.1.0" shell-words = "1.1.0"
homedir = "0.3.4"

View File

@ -66,7 +66,8 @@ Edit the server properties of steptech
```bash ```bash
multi-ssh steptech -e server.properties multi-ssh steptech -e server.properties
``` ```
This will create a copy of the file in your `~/Downloads` directory. That directory can be changed using the `-d` flag. Note that the above command will create a `.mssh` folder in your current working directory. That directory can be
changed with the `-d` flag.
## Building from source ## Building from source

View File

@ -99,11 +99,9 @@ enum Command {
/// If omitted, the command will be taken from the environment variable `MSSH_EDITOR`. /// If omitted, the command will be taken from the environment variable `MSSH_EDITOR`.
#[arg(short, long)] #[arg(short, long)]
editor: Option<String>, editor: Option<String>,
/// The directory where to save the file to. /// The directory where to save the file to
/// #[arg(short = 'd', long, default_value = ".mssh/downloads")]
/// Default directory is `~/Downloads` working_directory: PathBuf,
#[arg(short = 'd', long)]
download_directory: Option<PathBuf>,
/// Override existing files in the working directory /// Override existing files in the working directory
#[arg(short = 'f', long = "override", default_value = "false")] #[arg(short = 'f', long = "override", default_value = "false")]
override_existing: bool, override_existing: bool,
@ -332,27 +330,13 @@ fn main() -> Result<(), String> {
Command::Editor { Command::Editor {
file, file,
editor, editor,
download_directory, working_directory,
override_existing, override_existing,
} => { } => {
//determine download directory
let download_directory = match download_directory {
Some(download_directory) => download_directory,
None => {
let home_dir = homedir::my_home()
.map_err(|e| format!("Failed to determine your home directory: {e}"))
.and_then(|home_dir| {
home_dir.ok_or("Failed to determine your home directory".to_string())
})
.map_err(|e| format!("Can't determine download directory: {e}"))?;
home_dir.join("Downloads")
}
};
//get editor //get editor
let editor = editor.ok_or(()).or_else(|_| env::var(EDITOR_ENV_VAR).map_err(|e| format!("You have not specified an editor. Please do so using the --editor flag or the {EDITOR_ENV_VAR} environment variable: {e}")))?; let editor = editor.ok_or(()).or_else(|_| env::var(EDITOR_ENV_VAR).map_err(|e| format!("You have not specified an editor. Please do so using the --editor flag or the {EDITOR_ENV_VAR} environment variable: {e}")))?;
fs::create_dir_all(&download_directory) fs::create_dir_all(&working_directory)
.map_err(|e| format!("failed to create working directory: {e}"))?; .map_err(|e| format!("failed to create working directory: {e}"))?;
//make sure file doesn't exist in working directory yet, or will be overridden //make sure file doesn't exist in working directory yet, or will be overridden
@ -361,7 +345,7 @@ fn main() -> Result<(), String> {
.ok_or("can only edit files, not directories")?; .ok_or("can only edit files, not directories")?;
'duplicate_check: { 'duplicate_check: {
if !override_existing if !override_existing
&& fs::read_dir(&download_directory) && fs::read_dir(&working_directory)
.map_err(|e| format!("failed to open working directory: {e}"))? .map_err(|e| format!("failed to open working directory: {e}"))?
.collect::<Result<Vec<_>, _>>() .collect::<Result<Vec<_>, _>>()
.map_err(|e| format!("error while querying working directory contents: {e}"))? .map_err(|e| format!("error while querying working directory contents: {e}"))?
@ -371,7 +355,7 @@ fn main() -> Result<(), String> {
let duplication_notification = format!( let duplication_notification = format!(
"A file with the name {} already exists in {}", "A file with the name {} already exists in {}",
file_name.to_string_lossy(), file_name.to_string_lossy(),
download_directory.to_string_lossy() working_directory.to_string_lossy()
); );
if !args.quiet { if !args.quiet {
@ -397,7 +381,7 @@ fn main() -> Result<(), String> {
log!(logger, "Downloading file from {}...", server.ssh_name); log!(logger, "Downloading file from {}...", server.ssh_name);
ShellCmd::new("scp") ShellCmd::new("scp")
.arg(osf!(&server.ssh_name) + ":" + server.server_directory_path.join(&file)) .arg(osf!(&server.ssh_name) + ":" + server.server_directory_path.join(&file))
.arg(&download_directory) .arg(&working_directory)
.run(&logger) .run(&logger)
.map_err(|e| format!("download failure: {e}"))?; .map_err(|e| format!("download failure: {e}"))?;
@ -405,9 +389,7 @@ fn main() -> Result<(), String> {
let mut shell_args = shell_words::split(&editor) let mut shell_args = shell_words::split(&editor)
.map_err(|e| format!("failed to parse editor command: {e}"))? .map_err(|e| format!("failed to parse editor command: {e}"))?
.into_iter() .into_iter()
.map(|part| { .map(|part| part.replace_with_os_str(FILE_PLACEHOLDER, working_directory.join(file_name)))
part.replace_with_os_str(FILE_PLACEHOLDER, download_directory.join(file_name))
})
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let command = shell_args.remove(0); let command = shell_args.remove(0);
@ -418,7 +400,7 @@ fn main() -> Result<(), String> {
//upload file again //upload file again
ShellCmd::new("scp") ShellCmd::new("scp")
.arg(download_directory.join(file_name)) .arg(working_directory.join(file_name))
.arg(osf!(&server.ssh_name) + ":" + server.server_directory_path.join(&file)) .arg(osf!(&server.ssh_name) + ":" + server.server_directory_path.join(&file))
.run(&logger) .run(&logger)
.map_err(|e| format!("failed to re-upload file: {e}"))?; .map_err(|e| format!("failed to re-upload file: {e}"))?;