Compare commits

..

5 commits

9 changed files with 133 additions and 11 deletions

View file

@ -1,7 +1,8 @@
# Winure: WSL inurement tools # Winure: WSL inurement tools
These are tools I use to use Windows primarily through WSL. 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`".
## `mkwin` ## `mkwin`

View file

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

6
man/justfile Normal file
View file

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

61
man/mkwin.1 Normal file
View file

@ -0,0 +1,61 @@
.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 .

32
man/path-convert.1 Normal file
View file

@ -0,0 +1,32 @@
.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] [package]
name = "mkwin" name = "mkwin"
version = "0.0.3" version = "0.0.4"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View file

@ -1,7 +1,8 @@
//! constants for flag arguments //! constants for flag arguments
pub const HELP: [&str;2] = ["-h", "--help"]; pub const HELP: [&str;2] = ["-h", "--help"];
pub const EMPTY: &str = "--empty"; pub const EMPTY: [&str;2] = ["-e", "--empty"];
pub const FIND_BIN: &str = "--find";
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"];

View file

@ -51,6 +51,13 @@ 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 // consume simple flags
let empty = args.contains(flag::EMPTY); let empty = args.contains(flag::EMPTY);
let quiet = args.contains(flag::QUIET); let quiet = args.contains(flag::QUIET);
@ -58,20 +65,25 @@ 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
target = format!("target=`find {root} -name '{arg}'`\n\"$target\"");
} 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() {
target = path.to_string_lossy().into(); let path: String = path.to_string_lossy().into();
target = format!("'{path}'");
} else { } else {
error::canonicalize_fail(arg); error::canonicalize_fail(arg);
return; return;
} }
}
} else { } else {
error::missing_target(); error::missing_target();
return; return;
} }
// construct output // 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 // handle forwarded arguments
if !forwarded.is_empty() { if !forwarded.is_empty() {
@ -115,6 +127,10 @@ flags:
--empty The resulting script will not pass arguments. --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 --pc=<flags> The resulting script will use the 'path-convert' tool to
convert arguments from UNIX to DOS, with the provided set of convert arguments from UNIX to DOS, with the provided set of
flags ('x' for no flags). flags ('x' for no flags).

View file

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