Compare commits

..

No commits in common. "c5625bf46c442bb2e777751feabbe628b81d36b6" and "63f8e69afca353b5f76e827c0d44df36b556c28a" have entirely different histories.

9 changed files with 11 additions and 133 deletions

View file

@ -1,8 +1,7 @@
# Winure: WSL inurement tools
These are tools I use to use Windows primarily through WSL. A lot of them
assume you have PowerShell somewhere in your `PATH` as "`pwsh`".
These are tools I use to use Windows primarily through WSL.
## `mkwin`

View file

@ -12,7 +12,6 @@ install TARGET='all' DIR="~/.bin/":
just install mkwin {{DIR}}
just install path-convert {{DIR}}
just install qdls {{DIR}}
just install man
else
just {{TARGET}}/install `realpath {{DIR}}`
fi

View file

@ -1,6 +0,0 @@
alias i := install
install DIR="(unused)":
sudo cp ./*.1 /usr/share/man/man1/

View file

@ -1,61 +0,0 @@
.Dd $Mdocdate$
.Dt MKWIN 1
.Os
.Sh NAME
.Nm mkwin
.Nd generate bash scripts for running Windows programs from WSL
.Sh SYNOPSIS
.Nm mkwin
.Op Fl hq
.Op Fl empty
.Op Fl -find Ar root
.Op Fl -pc Ar flags
.Op Fl -quiet
.Ar target
.Op Ar --\ args
.Sh DESCRIPTION
The
.Nm
utility generates bash scripts for executing Windows executables from WSL, and prints them to the standard output. The options are as follows:
.Bl -tag -width Ds
.It Ar --\ args
The resulting sript will forward the provided arguments.
.It Fl -empty
The resulting script will not pass arguments to the target binary.
.It Fl -find Ar root
The resulting script will locate the target binary in the given directory using
.Xr find 1 .
.It Fl h , Fl -help
Print a short help message.
.It Fl -pc Ar flags
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).
.It Fl q , Fl -quiet
The resulting script will redirect output to /dev/null and send the target to the background.
.El
.Sh EXIT STATUS
.Bl -tag -width Ds
.It 1
No
.Ar target
was provided.
.It 2
Path canonicalization failed; this typically indicates the
.Ar target
points to a file or directory that does not exist.
.El
.Sh EXAMPLES
Windows Explorer does not accept paths with spaces when executed from WSL. To generate a script to launch Windows Explorer:
.Pp
.Dl $ mkwin --pc=sqq /mnt/c/Windows/System32/explorer.exe > explorer.sh
.Pp
Windows Terminal's executable moves when updated. To generate a script to launch Windows Terminal:
.Pp
.Dl $ mkwin --empty --find='/mnt/c/Program Files/WindowsApps/Microsoft.WindowsTerminal*' WindowsTerminal.exe > terminal.sh
.Pp
.Sh SEE ALSO
.Xr find 1 ,
.Xr path-convert 1
.Sh AUTHORS
.An -nosplit
.An Valerie Wolfe Aq Mt sleeplessval@gmail.com .

View file

@ -1,32 +0,0 @@
.Dd $Mdocdate$
.Dt PATH-CONVERT 1
.Os
.Sh NAME
.Nm path-convert
.Nd canonicalize and convert Unix paths for use with DOS programs
.Sh SYNOPSIS
.Nm path-convert
.Op Fl hnqs
.Ar
.Sh DESCRIPTION
The
.Nm
utility converts UNIX paths to DOS, for command substituting paths when invoking Windows executables from the terminal in WSL. Its options are as follows:
.Bl -tag -width Ds
.It Fl h , Fl -help
Displays a short help text.
.It Fl n , Fl -network
Adds the WSL network path where appropriate.
.It Fl q , Fl -quotes
Surrounds each converted path with single quotes (-q) or double quotes (-qq).
.It Fl s , Fl -no-space
Uses DOS shortening for directories in the path whose name contains spaces.
.El
.Sh ENVIRONMENT
.Bl -tag -width Ds
.It Ev WSL_DISTRO_NAME
This should be auto-set by WSL, and contains the name of the current distribution.
.El
.Sh AUTHORS
.An -nosplit
.An Valerie Wolfe Aq Mt sleeplessval@gmail.com .

View file

@ -1,6 +1,6 @@
[package]
name = "mkwin"
version = "0.0.4"
version = "0.0.3"
edition = "2021"
[dependencies]

View file

@ -1,8 +1,7 @@
//! constants for flag arguments
pub const HELP: [&str;2] = ["-h", "--help"];
pub const EMPTY: [&str;2] = ["-e", "--empty"];
pub const FIND_BIN: &str = "--find";
pub const EMPTY: &str = "--empty";
pub const PATH_CONVERT: &str = "--pc";
pub const QUIET: [&str;2] = ["-q", "--quiet"];

View file

@ -51,13 +51,6 @@ pub fn main() {
}
}
// consume find binary flag
let find_bin: Option<String>;
match args.value_from_str::<&str, String>(flag::FIND_BIN) {
Ok(inner) => find_bin = Some(inner),
_ => find_bin = None
}
// consume simple flags
let empty = args.contains(flag::EMPTY);
let quiet = args.contains(flag::QUIET);
@ -65,17 +58,12 @@ pub fn main() {
// get target executable
let target: String;
if let Ok(Some(arg)) = args.subcommand() {
if let Some(root) = find_bin { // handle find binary flag
target = format!("target=`find {root} -name '{arg}'`\n\"$target\"");
} else { // handle normal path
let path = Path::new(&arg);
if let Ok(path) = path.canonicalize() {
let path: String = path.to_string_lossy().into();
target = format!("'{path}'");
} else {
error::canonicalize_fail(arg);
return;
}
let path = Path::new(&arg);
if let Ok(path) = path.canonicalize() {
target = path.to_string_lossy().into();
} else {
error::canonicalize_fail(arg);
return;
}
} else {
error::missing_target();
@ -83,7 +71,7 @@ pub fn main() {
}
// construct output
print!("#!/usr/bin/bash\n# generated with: mkwin{arg_string}\n\n{target}");
print!("#!/usr/bin/bash\n# generated with: mkwin{arg_string}\n\n'{target}'");
// handle forwarded arguments
if !forwarded.is_empty() {
@ -127,10 +115,6 @@ flags:
--empty The resulting script will not pass arguments.
--find=<root> The resulting script will use the 'find' utility to locate
the target binary in the given directory. The value given by
root is passed verbatim to 'find', unexpanded.
--pc=<flags> The resulting script will use the 'path-convert' tool to
convert arguments from UNIX to DOS, with the provided set of
flags ('x' for no flags).

View file

@ -1,8 +1,4 @@
#!/usr/bin/bash
if [ "$#" -eq 0 ]; then
pwsh
else
pwsh -C "$@"
fi
pwsh -C "$@"