This document provides comprehensive information about wsl-utils configuration, advanced usage, environment variables, and troubleshooting.
Core System Variables:
WSLUTIL_DIR- Installation directory (auto-detected from script location)WSL_INTEROP- WSL interop socket path (default:/run/WSL/1_interop)
Windows Environment Variables:
WIN_USERPROFILE- Windows user profile path (e.g.,/mnt/c/Users/username)WIN_WINDIR- Windows directory path (e.g.,/mnt/c/Windows)WIN_PROGRAMFILES- Program Files directory (e.g.,/mnt/c/Program Files)WIN_PROGRAMFILES_X86- Program Files (x86) directoryWIN_LOCALAPPDATA- User's Local AppData directoryWIN_APPDATA- User's Roaming AppData directoryWIN_ENV[]- Associative array containing Windows environment variables
- The
WIN_ENV[]associative array is only available in the main shell session and is not passed to subshells or scripts - Logging is opt-in and must be enabled with
WSLUTIL_DEBUG=1environment variable
wsl-utils supports user-specific configuration files that override system defaults. This allows customization without modifying the installed files.
Configuration File Locations:
- System Configuration:
${WSLUTIL_DIR}/config/ - User Configuration:
${XDG_CONFIG_HOME:-$HOME/.config}/wslutil/
Supported Configuration Files:
conf.yml- Windows executable configuration forwslutil setupwin-run.yml- Aliases forwin-runcommand
Controls which Windows executables get symlinked by wslutil setup:
direct_links:
- cmd.exe
- ipconfig.exe
- ping.exe
shims:
- notepad.exe
- explorer.exeCategories:
- direct_links: Create direct symlinks to Windows executables
- shims: Create symlinks that route through
win-runfor path conversion
Define custom aliases for Windows applications:
aliases:
brave.exe:
path: ${WIN_PROGRAMFILES}/BraveSoftware/Brave-Browser/Application/brave.exe
options: null
devenv.exe:
path: ${WIN_PROGRAMFILES}/Microsoft Visual Studio/2022/Community/Common7/IDE/devenv.exe
options: "--startup-option"Fields:
- path: Full path to the Windows executable (supports environment variable expansion)
- options: Additional command-line options to prepend (optional)
Usage Example:
# Using custom config file
wslutil setup -c ~/.config/wslutil/conf.yml
# Win-run will automatically resolve aliases
win-run brave.exe https://example.comThe wslpath-drive utility extends standard wslpath functionality with support for Windows drive substitution:
# Standard conversion
wslpath-drive -w /home/user/file.txt
# Output: \\wsl.localhost\distro\home\user\file.txt
# With drive substitution (if Z: maps to \\wsl.localhost\distro)
wslpath-drive -W /home/user/file.txt
# Output: Z:\home\user\file.txt
# Forward slash version
wslpath-drive -M /mnt/c/projects
# Output: Z:/home/user/file.txt (if substituted)Pattern 1: Direct Command Execution
# Execute Windows commands with automatic path conversion
win-run notepad.exe /home/user/file.txt
win-run powershell.exe -Command "Get-Process"Pattern 2: Pipeline Integration
# Process Windows command output
win-run cmd.exe /c dir | grep ".txt"
win-run powershell.exe -Command "Get-Service" | grep "Running"Pattern 3: Clipboard Workflows
# Copy-paste workflows
ls -la | win-copy # Copy to Windows clipboard
win-paste | grep "important" # Search clipboard content
win-paste > restored.txt # Save clipboard to filePattern 4: WSL System Monitoring
# Monitor WSL distribution uptime (not VM uptime)
wslutil uptime # Standard uptime format
wslutil uptime --pretty # Human-readable format
wslutil uptime --since # Show WSL distro start timeAdding Custom Subcommands:
Create executable scripts named wslutil-<name> in your PATH:
#!/bin/bash
# ~/.local/bin/wslutil-mycommand
echo "This is my custom wslutil command"Usage: wslutil mycommand
Custom Windows Integration:
Create aliases in win-run.yml for Windows applications:
aliases:
myapp.exe:
path: ${WIN_PROGRAMFILES}/MyApp/bin/myapp.exe
options: "--default-config"Environment Variables Not Set
# Check if environment is loaded
echo $WIN_USERPROFILE
# Manually load if needed
eval "$(wslutil shellenv)"WSL Interop Issues
# Check WSL interop status
wslutil doctor
# Verify interop socket
ls -la $WSL_INTEROPWSL Distribution Monitoring
# Check WSL distribution uptime (different from system uptime)
wslutil uptime # Shows WSL distro uptime, not VM
uptime # Shows underlying system/VM uptime
# Useful for troubleshooting WSL restarts vs system reboots
wslutil uptime --since # When did WSL distro last start?Path Conversion Problems
# Test path conversion
wslpath-drive -w /home/user/test.txt
# Check for drive substitution
win-run subst.exeEncoding Issues with Windows Output
# Use win-run for automatic encoding handling
win-run cmd.exe /c dir
# Manual encoding conversion (advanced)
powershell.exe -Command "Get-Process" | win-utf8Enable debug logging:
export WSLUTIL_DEBUG=1
win-run notepad.exe /tmp/test.txt
# Check logs in ~/.local/state/wslutil/win-run.logOptimizing Windows Command Execution:
- Use
win-run --rawfor binary output to skip encoding conversion - Use
win-run --plainto skip automatic path conversion when not needed - Cache frequently used Windows executable paths in win-run.yml aliases
This project includes comprehensive tests using the Bats (Bash Automated Testing System) framework.
Prerequisites:
# Install bats-core (example for Ubuntu/Debian)
sudo apt-get install bats
# Or install via npm
npm install -g batsExecute Tests:
# Run all tests
make test
# Run specific test file
bats test/wslutil-setup.bats
# Verbose output
bats --verbose test/test/- Test files (*.bats)test/fixtures/- Test data and configuration filestest/helpers/- Common test utilities
Test Categories:
- Unit tests for individual script functions
- Integration tests for command workflows
- Configuration validation tests
- Cross-platform compatibility tests
WSL1:
- Direct Windows filesystem access via
/mnt/c/ - No WSLg support (manual clipboard handling)
WSL2:
- Network-based Windows integration
- WSLg support for native clipboard operations
- Enhanced security model
Windows 10:
- Basic WSL interop support
- Manual PATH management for Windows executables
Windows 11:
- Enhanced WSL integration
- Improved performance for cross-system operations
- Better Unicode support
- Fork the repository
- Clone your fork:
git clone <your-fork-url> - Create a feature branch:
git checkout -b feature-name - Make changes and add tests
- Run tests:
make test - Commit with conventional commit format
- Submit a pull request
- Use
shellcheckfor shell script linting - Follow existing code formatting patterns
- Add documentation for new features
- Include tests for new functionality
This project uses git-cliff for changelog generation:
# Generate changelog for new version
git cliff --tag v0.6.0 --output CHANGELOG.md
# Tag and push
git tag v0.6.0
git push origin v0.6.0This project is licensed under the MIT License - see the LICENSE file for details.