Skip to content

Instantly share code, notes, and snippets.

@cpriest
Created April 8, 2021 18:22
Show Gist options
  • Save cpriest/b08543648ba513d977e6c54e23f9f682 to your computer and use it in GitHub Desktop.
Save cpriest/b08543648ba513d977e6c54e23f9f682 to your computer and use it in GitHub Desktop.
Command wrapper for PowerShell/OpenSSH to allow for ssh remote commands to work properly by unwrapping $0
;@Ahk2Exe-ConsoleApp
SendMode Input
SetWorkingDir, %A_ScriptDir%
; This script exists because remote ssh command calls when passed to OpenSSH for Windows (PowerShell/OpenSSH)
; The remote command is wrapped in quotes which does not work correctly. This simply unwraps them and passes
; to wsl.exe. ssh {host} echo 'hello world' = wsl.exe "echo 'hello world'"
; This script changes that to: wsl.exe echo 'hello world'
;
; NOTE: You probably will need to compile this with ahk2exe and run it as ssh-wsl.exe
;
; Registry configuration
; HKEY_LOCAL_MACHINE\SOFTWARE\OpenSSH\DefaultShell = {path_to_ssh-wsl.exe}
; HKEY_LOCAL_MACHINE\SOFTWARE\OpenSSH\DefaultShellCommandOption = --
; Get remaining arguments and stuff into ArgPass
RemArgs = %0%
ArgPass :=
Loop %RemArgs% {
Arg := %A_Index%
ArgPass := ArgPass " " Arg
}
Command := "wsl.exe " ArgPass
; stdout := FileOpen("*", "w `n")
; stdout.WriteLine("Running Command: ->" Command "<-`n")
; stdout.Read(0) ; Flush the write buffer.
RunWait, % Command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment