Compare commits
No commits in common. "32731b72b13e016dcad2aa4aefb8b7647fb1481a" and "5bdeabbe760149216716b258aab407a0c5ae559c" have entirely different histories.
32731b72b1
...
5bdeabbe76
11 changed files with 13 additions and 122 deletions
|
@ -4,10 +4,6 @@
|
|||
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`".
|
||||
|
||||
## `dos-var`
|
||||
|
||||
Gets Windows environment variables from DOS.
|
||||
|
||||
## `env-share`
|
||||
|
||||
A hacked-together utility for sending WSL variables back to Windows
|
||||
|
@ -40,4 +36,5 @@ A feature-barren DOS clone of `ls` that hides Windows hidden files. Relies on
|
|||
- `explorer.sh`: Launch explorer from WSL.
|
||||
- `pwsh.sh`: Launch PowerShell Core.
|
||||
- `terminal.sh`: Launch Windows Terminal.
|
||||
- `userprofile.sh`: Get the Windows user profile directory (`%USERPROFILE%`).
|
||||
|
||||
|
|
2
dos-var/.gitignore
vendored
2
dos-var/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
/target
|
||||
Cargo.lock
|
|
@ -1,15 +0,0 @@
|
|||
[package]
|
||||
name = "dos-var"
|
||||
version = "0.0.2"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
pico-args = "0.5.0"
|
||||
|
||||
[profile.release]
|
||||
opt-level = 's'
|
||||
codegen-units = 1
|
||||
debug = false
|
||||
lto = true
|
||||
panic = "abort"
|
||||
strip = "symbols"
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
alias b := build
|
||||
alias i := install
|
||||
|
||||
build:
|
||||
cargo build --release
|
||||
|
||||
install DIR: build
|
||||
cp ./target/release/dos-var "{{DIR}}/dos-var"
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
use std::process::exit;
|
||||
|
||||
pub fn not_found(target: &String) {
|
||||
eprintln!("dos-var: %{target}% has no value");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
pub fn missing_arg() {
|
||||
eprintln!("dos-var: no argument found");
|
||||
exit(2);
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
use std::process::Command;
|
||||
|
||||
use pico_args::Arguments;
|
||||
|
||||
mod error;
|
||||
|
||||
const CMD: &str = "/mnt/c/Windows/System32/cmd.exe";
|
||||
|
||||
const FLAG_PATH: [&str; 2] = [ "-p", "--path" ];
|
||||
|
||||
pub fn main() {
|
||||
let mut args = Arguments::from_env();
|
||||
|
||||
let convert_path = args.contains(FLAG_PATH);
|
||||
|
||||
if let Ok(Some(target)) = args.subcommand() {
|
||||
let cmd = Command::new(CMD)
|
||||
.current_dir("/mnt/c/")
|
||||
.arg( format!("/C echo %{target}%") )
|
||||
.output();
|
||||
if let Ok(output) = cmd {
|
||||
if let Ok(stdout) = String::from_utf8(output.stdout) {
|
||||
// trim output
|
||||
let stdout = stdout.trim_end_matches("\"\r\n");
|
||||
// catch empty variable case
|
||||
if stdout == format!("%{target}%") { error::not_found(&target); }
|
||||
|
||||
// handle path flag and write
|
||||
let path =
|
||||
if convert_path {
|
||||
stdout
|
||||
.replace("\\", "/")
|
||||
.replace("C:/", "/mnt/c/")
|
||||
} else { stdout.to_owned() };
|
||||
println!("{path}");
|
||||
}
|
||||
}
|
||||
} else { error::missing_arg(); }
|
||||
}
|
||||
|
1
justfile
1
justfile
|
@ -9,7 +9,6 @@ install TARGET='all' DIR="~/.bin/":
|
|||
#!/usr/bin/bash
|
||||
if [[ {{TARGET}} == 'all' ]]; then
|
||||
just install scripts {{DIR}}
|
||||
just install dos-var {{DIR}}
|
||||
just install env-share {{DIR}}
|
||||
just install mkwin {{DIR}}
|
||||
just install path-convert {{DIR}}
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
.Dd $Mdocdate$
|
||||
.Dt DOS-VAR 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm dos-var
|
||||
.Nd gets DOS environment variables from WSL
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl p
|
||||
.Ar variable
|
||||
.Sh
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility gets a DOS environment variable from within WSL. It can also convert paths to UNIX.
|
||||
.Bl -tag -width Ds
|
||||
.It Fl p , Fl -path
|
||||
The target DOS variable contains a path, and will be converted.
|
||||
.It Ar variable
|
||||
The name of the target DOS variable.
|
||||
.El
|
||||
.Sh EXIT STATUS
|
||||
.Bl -tag -width Ds
|
||||
.It 1
|
||||
The target variable is empty.
|
||||
.It 2
|
||||
No target variable was provided.
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
Navigate to the Windows user directory:
|
||||
.Pp
|
||||
.Dl $ cd `dos-var -p USERPROFILE`
|
||||
.Pp
|
||||
.Sh Authors
|
||||
.An -nosplit
|
||||
.An Valerie Wolfe Aq Mt sleeplessval@gmail.com
|
|
@ -7,4 +7,5 @@ install DIR="~/.bin":
|
|||
cp explorer.sh {{DIR}}/explorer
|
||||
cp pwsh.sh {{DIR}}/pwsh
|
||||
cp terminal.sh {{DIR}}/terminal
|
||||
cp userprofile.sh {{DIR}}/userprofile
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ fi
|
|||
|
||||
# fall back to user installation
|
||||
if [ -z ${PWSH+x} ]; then
|
||||
PWSH="`dos-var -p USERPROFILE`/AppData/Local/Microsoft/WindowsApps/pwsh.exe"
|
||||
PWSH="`userprofile`/AppData/Local/Microsoft/WindowsApps/pwsh.exe"
|
||||
fi
|
||||
|
||||
# run target
|
||||
|
|
10
scripts/userprofile.sh
Executable file
10
scripts/userprofile.sh
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/bash
|
||||
|
||||
# absolutely monstrous string hackery
|
||||
# get %USERPROFILE% using cmd and convert that path
|
||||
USERPROFILE=`/mnt/c/Windows/System32/cmd.exe '/C' 'echo %USERPROFILE%' 2> /dev/null`
|
||||
USERPROFILE=${USERPROFILE//\\//} # replace '\' separators with '/'
|
||||
USERPROFILE=/mnt/c/${USERPROFILE#C:/} # replace 'C:/' with '/mnt/c/'
|
||||
USERPROFILE=${USERPROFILE%$'\r'} # strip carriage return
|
||||
echo $USERPROFILE
|
||||
|
Loading…
Reference in a new issue