Inspired by Winsomnia-ssh but works without python (just uses bash ans wsl). Usage
- Set Powershell path in
winsomnia-nopython.sh
- Set (absolute WSL) path to
keep_awake.ps1
inwinsomnia-nopython.sh
- Add the line
. /path/to/my-winsomnia.sh
to your~/.bashrc
or other shell initialization script. The.
prefix is crucial.
Whenever a new shell is initialized, the script checks if it is inside an ssh session. If that is the case, a Powershell child process is started that sets the SetThreadExecutionState
to ES_CONTINUOUS | ES_SYSTEM_REQUIRED
. This state is active until the windows thread exits. Fortunately, the windows thread will be killed when the corresponding linux process is killed, which is done using the trap ... EXIT
.