#!/bin/sh # The MIT License (MIT) # # Copyright (c) 2026 pacman64 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # pwsl - Power Windows Subsystem for Linux (`power-weasel`) # # Add WSL-specific live-shell shortcuts/commands by sourcing this script. # # To use this script, you're supposed to `source` it, so its definitions # stay for your whole shell session: for that, you can run `source pwsl` # or `. pwsl` (no quotes either way) directly or at shell startup. case "$1" in -h|--h|-help|--help) awk '/^# +pwsl /, /^$/ { gsub(/^# ?/, ""); print }' "$0" ;; esac # dash doesn't support regex-matching syntax, forcing to use case statements case "$0" in -bash|-dash|-sh|bash|dash|sh|/bin/sh) # script is being sourced with bash, dash, or ash, which is good : ;; *) case "$ZSH_EVAL_CONTEXT" in *:file) # script is being sourced with zsh, which is good : ;; *) # script is being run normally, which is a waste of time printf "\033[7mDon't run this script directly: instead source it\033[0m\n" printf "\033[7mby running '. pwsl' (without the single quotes).\033[0m\n" printf "\n" printf "\033[7mBefore doing that, you may want to see the help,\033[0m\n" printf "\033[7mby running 'pwsl -h' (without the single quotes).\033[0m\n" # exiting during shell-startup may deny shell access, even if # the script is being run, instead of being sourced directly ;; esac ;; esac if [ ! -e /usr/bin/wslinfo ]; then printf "\033[7mpwsl: WSL doesn't seem to be running.\033[0m\n" fi # Windows Subsystem for Linux alias wsl='/mnt/c/Windows/System32/wsl.exe' # Windows Subsystem for Linux OFF alias wsloff='wsl --shutdown' # Empty Clipboard ec() { /mnt/c/Windows/System32/clip.exe < /dev/null; } # find the LAN (local-area network) IP address for this device lanip() { /mnt/c/Windows/System32/ipconfig.exe \ | awk '/192\.[0-9\.]+\r?$/ { print $NF }' } # open/pop-up files, GUI file-explorers for folders, or web-browsers for URIs open() { local a local s='s-/$--; s-/-\\-g; s-^/mnt/([A-Ia-i])/-\1:\\-' for a in "${@:-.}"; do /mnt/c/Windows/System32/cmd.exe /c start "$(echo "$a" | sed -E "$s")" done | cat } # voice-synthesize plain-text say() { local p local w='/mnt/c/Windows/System32/WindowsPowerShell/' p="$(find $w -name powershell.exe -type f)" awk 1 "$@" \ | "${p}" -noprofile -command ' Add-Type -AssemblyName System.Speech $s = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer foreach ($line in $Input) { $s.Speak($line) } ' | cat } # Show It: fixes my `si` script to use win-python to open browser tabs si() { if [ $# -eq 0 ]; then wsl --cd "$(dirname "$(which si)")" "$(which python.exe)" si else open "$@" fi } # turn wsl/unix-style full-paths into WINdows-style full-PATHS winpaths() { awk 1 "$@" | sed -E 's-/mnt/(.)/-\u\1:/-'; }