diff --git a/utils/bin/npiperelay b/utils/bin/npiperelay new file mode 100644 index 0000000..e0302e3 Binary files /dev/null and b/utils/bin/npiperelay differ diff --git a/utils/bin/start b/utils/bin/start index d7e8b01..4b782df 100644 --- a/utils/bin/start +++ b/utils/bin/start @@ -1,3 +1,49 @@ #!/bin/sh -exec ssh-agent tmux new-session -A -t main "$@" +usage () { + echo "usage: $0 [-w] [-h]" + echo " -w use the WSL ssh-agent instead of OpenSSH for Windows" + echo " -h show help and exit" +} + +# Use OpenSSH for Windows by default. +WSL_SSH_AGENT=false + +while getopts ":wh" arg; do + case "$arg" in + w) + WSL_SSH_AGENT=true + ;; + + h) + >&2 usage + exit 0 + ;; + + ?) + >&2 echo "ERROR: unknown option -$OPTARG" + >&2 usage + exit 1 + ;; + esac +done + +if [ "$WSL_SSH_AGENT" = true ]; then + exec ssh-agent tmux new-session -A -t main "$@" +fi + +require() { + if ! command -v "$@" >/dev/null 2>&1; then + >&2 echo "ERROR: required command not found: $1" + exit 1 + fi +} + +require socat +require npiperelay + +# Forward SSH Agent requests from withitn WSL to OpenSSH for Windows, based on: +# https://stuartleeks.com/posts/wsl-ssh-key-forward-to-windows/ +export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock +socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"npiperelay -ei -s //./pipe/openssh-ssh-agent",nofork & +exec tmux new-session -A -t main "$@"