mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Added CLI options to set starting working directory on both local and remote hosts
This commit is contained in:
@@ -19,6 +19,7 @@ Released on ???
|
|||||||
|
|
||||||
- Enhancements:
|
- Enhancements:
|
||||||
- Default choice for deleting file set to "NO" (way too easy to delete files by mistake)
|
- Default choice for deleting file set to "NO" (way too easy to delete files by mistake)
|
||||||
|
- Added CLI options to set starting workind directory on both local and remote hosts
|
||||||
|
|
||||||
## 0.3.2
|
## 0.3.2
|
||||||
|
|
||||||
|
|||||||
@@ -163,6 +163,8 @@ brew install termscp
|
|||||||
|
|
||||||
TermSCP can be started with the following options:
|
TermSCP can be started with the following options:
|
||||||
|
|
||||||
|
`termscp [options]... [protocol://user@address:port] [local-wrkdir] [remote-wrkdir]`
|
||||||
|
|
||||||
- `-P, --password <password>` if address is provided, password will be this argument
|
- `-P, --password <password>` if address is provided, password will be this argument
|
||||||
- `-v, --version` Print version info
|
- `-v, --version` Print version info
|
||||||
- `-h, --help` Print help page
|
- `-h, --help` Print help page
|
||||||
@@ -171,6 +173,8 @@ TermSCP can be started in two different mode, if no extra arguments is provided,
|
|||||||
|
|
||||||
Alternatively, the user can provide an address as argument to skip the authentication form and starting directly the connection to the remote server.
|
Alternatively, the user can provide an address as argument to skip the authentication form and starting directly the connection to the remote server.
|
||||||
|
|
||||||
|
If address argument is provided you can also provide the start working directory for both local and remote hosts.
|
||||||
|
|
||||||
### Address argument 🌎
|
### Address argument 🌎
|
||||||
|
|
||||||
The address argument has the following syntax:
|
The address argument has the following syntax:
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ impl ActivityManager {
|
|||||||
protocol: FileTransferProtocol,
|
protocol: FileTransferProtocol,
|
||||||
username: Option<String>,
|
username: Option<String>,
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
|
entry_directory: Option<PathBuf>,
|
||||||
) {
|
) {
|
||||||
self.ftparams = Some(FileTransferParams {
|
self.ftparams = Some(FileTransferParams {
|
||||||
address,
|
address,
|
||||||
@@ -91,6 +92,7 @@ impl ActivityManager {
|
|||||||
protocol,
|
protocol,
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
|
entry_directory,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,6 +166,7 @@ impl ActivityManager {
|
|||||||
_ => Some(activity.password.clone()),
|
_ => Some(activity.password.clone()),
|
||||||
},
|
},
|
||||||
protocol: activity.protocol,
|
protocol: activity.protocol,
|
||||||
|
entry_directory: None, // Has use only when accessing with address
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/main.rs
21
src/main.rs
@@ -58,7 +58,9 @@ use filetransfer::FileTransferProtocol;
|
|||||||
/// Print usage
|
/// Print usage
|
||||||
|
|
||||||
fn print_usage(opts: Options) {
|
fn print_usage(opts: Options) {
|
||||||
let brief = String::from("Usage: termscp [options]... [protocol://user@address:port]");
|
let brief = String::from(
|
||||||
|
"Usage: termscp [options]... [protocol://user@address:port] [local-wrkdir] [remote-wrkdir]",
|
||||||
|
);
|
||||||
print!("{}", opts.usage(&brief));
|
print!("{}", opts.usage(&brief));
|
||||||
println!("\nPlease, report issues to <https://github.com/veeso/termscp>");
|
println!("\nPlease, report issues to <https://github.com/veeso/termscp>");
|
||||||
}
|
}
|
||||||
@@ -120,6 +122,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
// Check free args
|
// Check free args
|
||||||
let extra_args: Vec<String> = matches.free;
|
let extra_args: Vec<String> = matches.free;
|
||||||
|
// Remote argument
|
||||||
if let Some(remote) = extra_args.get(0) {
|
if let Some(remote) = extra_args.get(0) {
|
||||||
// Parse address
|
// Parse address
|
||||||
match utils::parser::parse_remote_opt(remote) {
|
match utils::parser::parse_remote_opt(remote) {
|
||||||
@@ -137,6 +140,20 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Local directory
|
||||||
|
if let Some(localdir) = extra_args.get(1) {
|
||||||
|
// Change working directory if local dir is set
|
||||||
|
let localdir: PathBuf = PathBuf::from(localdir);
|
||||||
|
if let Err(err) = env::set_current_dir(localdir.as_path()) {
|
||||||
|
eprintln!("Bad working directory argument: {}", err);
|
||||||
|
std::process::exit(255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Remote directory
|
||||||
|
let remote_wrkdir: Option<PathBuf> = match extra_args.get(2) {
|
||||||
|
Some(p) => Some(PathBuf::from(p)),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
// Get working directory
|
// Get working directory
|
||||||
let wrkdir: PathBuf = match env::current_dir() {
|
let wrkdir: PathBuf = match env::current_dir() {
|
||||||
Ok(dir) => dir,
|
Ok(dir) => dir,
|
||||||
@@ -174,7 +191,7 @@ fn main() {
|
|||||||
};
|
};
|
||||||
// Set file transfer params if set
|
// Set file transfer params if set
|
||||||
if let Some(address) = address {
|
if let Some(address) = address {
|
||||||
manager.set_filetransfer_params(address, port, protocol, username, password);
|
manager.set_filetransfer_params(address, port, protocol, username, password, remote_wrkdir);
|
||||||
}
|
}
|
||||||
// Run
|
// Run
|
||||||
manager.run(start_activity);
|
manager.run(start_activity);
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ pub struct FileTransferParams {
|
|||||||
pub protocol: FileTransferProtocol,
|
pub protocol: FileTransferProtocol,
|
||||||
pub username: Option<String>,
|
pub username: Option<String>,
|
||||||
pub password: Option<String>,
|
pub password: Option<String>,
|
||||||
|
pub entry_directory: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### InputField
|
/// ### InputField
|
||||||
|
|||||||
@@ -67,6 +67,14 @@ impl FileTransferActivity {
|
|||||||
.as_ref(),
|
.as_ref(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// Try to change directory to entry directory
|
||||||
|
let mut remote_chdir: Option<PathBuf> = None;
|
||||||
|
if let Some(entry_directory) = &self.params.entry_directory {
|
||||||
|
remote_chdir = Some(entry_directory.clone());
|
||||||
|
}
|
||||||
|
if let Some(entry_directory) = remote_chdir {
|
||||||
|
self.remote_changedir(entry_directory.as_path(), false);
|
||||||
|
}
|
||||||
// Set state to explorer
|
// Set state to explorer
|
||||||
self.popup = None;
|
self.popup = None;
|
||||||
self.reload_remote_dir();
|
self.reload_remote_dir();
|
||||||
@@ -607,13 +615,14 @@ impl FileTransferActivity {
|
|||||||
// Restore index
|
// Restore index
|
||||||
self.local.set_abs_index(prev_index);
|
self.local.set_abs_index(prev_index);
|
||||||
// Set index; keep if possible, otherwise set to last item
|
// Set index; keep if possible, otherwise set to last item
|
||||||
self.local.set_abs_index(match self.local.get_current_file() {
|
self.local
|
||||||
Some(_) => self.local.get_index(),
|
.set_abs_index(match self.local.get_current_file() {
|
||||||
None => match self.local.count() {
|
Some(_) => self.local.get_index(),
|
||||||
0 => 0,
|
None => match self.local.count() {
|
||||||
_ => self.local.count() - 1,
|
0 => 0,
|
||||||
},
|
_ => self.local.count() - 1,
|
||||||
});
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.log_and_alert(
|
self.log_and_alert(
|
||||||
@@ -636,13 +645,14 @@ impl FileTransferActivity {
|
|||||||
// Restore index
|
// Restore index
|
||||||
self.remote.set_abs_index(prev_index);
|
self.remote.set_abs_index(prev_index);
|
||||||
// Set index; keep if possible, otherwise set to last item
|
// Set index; keep if possible, otherwise set to last item
|
||||||
self.remote.set_abs_index(match self.remote.get_current_file() {
|
self.remote
|
||||||
Some(_) => self.remote.get_index(),
|
.set_abs_index(match self.remote.get_current_file() {
|
||||||
None => match self.remote.count() {
|
Some(_) => self.remote.get_index(),
|
||||||
0 => 0,
|
None => match self.remote.count() {
|
||||||
_ => self.remote.count() - 1,
|
0 => 0,
|
||||||
},
|
_ => self.remote.count() - 1,
|
||||||
});
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.log_and_alert(
|
self.log_and_alert(
|
||||||
|
|||||||
Reference in New Issue
Block a user