Compare commits
No commits in common. "eb675928a7b3ac6fdfc56b38645133f0ad43c81d" and "ed26c60ceb2dd09f5feaaa62ce753a73494f88cb" have entirely different histories.
eb675928a7
...
ed26c60ceb
6 changed files with 26 additions and 24 deletions
|
@ -10,7 +10,6 @@
|
||||||
.Op Fl -find Ar root
|
.Op Fl -find Ar root
|
||||||
.Op Fl -pc Ar flags
|
.Op Fl -pc Ar flags
|
||||||
.Ar target
|
.Ar target
|
||||||
.Op Fl -or Ar alt
|
|
||||||
.Op Ar --\ args
|
.Op Ar --\ args
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
|
@ -30,8 +29,6 @@ The resulting script will locate the target binary in the given directory using
|
||||||
.Xr find 1 .
|
.Xr find 1 .
|
||||||
.It Fl h , Fl -help
|
.It Fl h , Fl -help
|
||||||
Print a short help message.
|
Print a short help message.
|
||||||
.It Fl -or Ar fallback
|
|
||||||
The resulting script will fall back to the provided argument if the target is not executable.
|
|
||||||
.It Fl -pc Ar flags
|
.It Fl -pc Ar flags
|
||||||
The resulting script will pass the arguments converted with
|
The resulting script will pass the arguments converted with
|
||||||
.Xr path-convert 1 . path-convert will be invoked with the provided flags forwarded (use 'x' to forward no flags).
|
.Xr path-convert 1 . path-convert will be invoked with the provided flags forwarded (use 'x' to forward no flags).
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "mkwin"
|
name = "mkwin"
|
||||||
version = "0.2.0"
|
version = "0.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
/// no argument for target; code 1
|
/// no argument for target; code 1
|
||||||
pub fn missing_target() -> ! {
|
pub fn missing_target() {
|
||||||
eprintln!("mkwin: missing target");
|
eprintln!("mkwin: missing target");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// failed to canonicalize target path; code 2
|
/// failed to canonicalize target path; code 2
|
||||||
pub fn canonicalize_fail(target: String) -> ! {
|
pub fn canonicalize_fail(target: String) {
|
||||||
eprintln!("mkwin: failed to canonicalze '{target}'--does the file exist?");
|
eprintln!("mkwin: failed to canonicalze '{target}'--does the file exist?");
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ pub const HELP: [&str;2] = ["-h", "--help"];
|
||||||
pub const EMPTY: [&str;2] = ["-e", "--empty"];
|
pub const EMPTY: [&str;2] = ["-e", "--empty"];
|
||||||
pub const ENV_SHARE: [&str;2] = ["-E", "--env-share"];
|
pub const ENV_SHARE: [&str;2] = ["-E", "--env-share"];
|
||||||
pub const FIND_BIN: &str = "--find";
|
pub const FIND_BIN: &str = "--find";
|
||||||
pub const OR: &str = "--or";
|
|
||||||
pub const PATH_CONVERT: &str = "--pc";
|
pub const PATH_CONVERT: &str = "--pc";
|
||||||
pub const QUIET: [&str;2] = ["-q", "--quiet"];
|
pub const QUIET: [&str;2] = ["-q", "--quiet"];
|
||||||
|
|
||||||
|
|
|
@ -66,30 +66,29 @@ pub fn main() {
|
||||||
// get target executable
|
// get target executable
|
||||||
let target: String;
|
let target: String;
|
||||||
if let Ok(Some(arg)) = args.subcommand() {
|
if let Ok(Some(arg)) = args.subcommand() {
|
||||||
if let Some(root) = &find_bin { // handle find binary flag
|
if let Some(root) = find_bin { // handle find binary flag
|
||||||
target = format!("`find {root} -name '{arg}'`");
|
target = format!("target=`find {root} -name '{arg}'`\n\"$target\"");
|
||||||
} else { // handle normal path
|
} else { // handle normal path
|
||||||
let path = Path::new(&arg);
|
let path = Path::new(&arg);
|
||||||
if let Ok(path) = path.canonicalize() {
|
if let Ok(path) = path.canonicalize() {
|
||||||
let path: String = path.to_string_lossy().into();
|
let path: String = path.to_string_lossy().into();
|
||||||
target = format!("'{path}'");
|
target = format!("'{path}'");
|
||||||
} else { error::canonicalize_fail(arg); }
|
} else {
|
||||||
|
error::canonicalize_fail(arg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error::missing_target();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else { error::missing_target(); }
|
|
||||||
|
|
||||||
let exec =
|
|
||||||
if let Ok(alt) = args.value_from_str::<&str, String>(flag::OR) {
|
|
||||||
format!("target={target}\nif [ ! -x \"$target\" ]; then\n\ttarget='{alt}'\nfi\n\n\"$target\"")
|
|
||||||
} else if find_bin.is_some() {
|
|
||||||
format!("\"{target}\"")
|
|
||||||
} else { target };
|
|
||||||
|
|
||||||
// construct output
|
// construct output
|
||||||
println!("#!/usr/bin/bash\n# generated with: mkwin{arg_string}\n");
|
println!("#!/usr/bin/bash\n# generated with: mkwin{arg_string}\n");
|
||||||
|
|
||||||
if env_share { println!("env-share 2> /dev/null\n"); }
|
if env_share { println!("env-share 2> /dev/null\n"); }
|
||||||
|
|
||||||
print!("{exec}");
|
print!("{target}");
|
||||||
|
|
||||||
// handle forwarded arguments
|
// handle forwarded arguments
|
||||||
if !forwarded.is_empty() {
|
if !forwarded.is_empty() {
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
# generated with: mkwin /mnt/c/Program Files/PowerShell/7/pwsh.exe -E --or /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
|
|
||||||
|
|
||||||
env-share 2> /dev/null
|
env-share 2> /dev/null
|
||||||
|
|
||||||
target='/mnt/c/Program Files/PowerShell/7/pwsh.exe'
|
# try to use system-wide version first.
|
||||||
if [ ! -x "$target" ]; then
|
PWSH='/mnt/c/Program Files/PowerShell/7/pwsh.exe'
|
||||||
target='/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe'
|
if [ ! -x "$PWSH" ]; then
|
||||||
|
unset PWSH
|
||||||
fi
|
fi
|
||||||
|
|
||||||
"$target" $@
|
# fall back to System32
|
||||||
|
if [ -z ${PWSH+x} ]; then
|
||||||
|
PWSH='/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# run target
|
||||||
|
"$PWSH" $@
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue