Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,28 @@ chmod 755 wsl2-ssh-agent

**If you are using ArchLinux, you can install the [wsl2-ssh-agent](https://aur.archlinux.org/packages/wsl2-ssh-agent) package from the AUR (maintained by @Hill-98).**

### 2. Modify `.bashrc` (or `.zshrc` if you are using `zsh`)
### 2. Modify your shell's rc file

#### bash or zsh

Add the following line to `.bashrc` (or `.zshrc` if you are using `zsh`).

```
eval $($HOME/wsl2-ssh-agent)
```

#### fish

Add the following lines to `config.fish`

```
if status is-login
$HOME/wsl2-ssh-agent | source
end
```

### 3. Reopen your terminal

Close and reopen the terminal and execute `ssh your-machine`.
The command should communicate with ssh-agent.exe service.

Expand Down
29 changes: 28 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (
"os/exec"
"os/signal"
"path/filepath"
"strings"
"syscall"
)

type config struct {
socketPath string
powershellPath string
format string
foreground bool
verbose bool
stop bool
Expand Down Expand Up @@ -76,6 +78,31 @@ func newConfig() *config {
return c
}

func getOutputFormat(format string) string {
if format == "auto" {
shell := os.Getenv("SHELL")
if strings.HasSuffix(shell, "fish") {
format = "fish"
} else if strings.HasSuffix(shell, "csh") {
format = "csh"
} else {
format = "sh"
}
}
switch format {
case "sh", "bash", "zsh":
return "SSH_AUTH_SOCK=%s; export SSH_AUTH_SOCK;"
case "csh", "tcsh":
return "setenv SSH_AUTH_SOCK %s"
case "fish":
return "set -x SSH_AUTH_SOCK %s"
default:
fmt.Printf("output format must be auto, bash, zsh, csh, tcsh, or fish\n")
os.Exit(1)
return ""
}
}

func (c *config) start() context.Context {
if c.version {
fmt.Printf("wsl2-ssh-agent %s\n", version)
Expand All @@ -86,7 +113,7 @@ func (c *config) start() context.Context {
parent := checkDaemonMode()

// script output
output := fmt.Sprintf("SSH_AUTH_SOCK=%s; export SSH_AUTH_SOCK;", c.socketPath)
output := fmt.Sprintf(getOutputFormat(c.format), c.socketPath)

// set up the log file
c.setupLogFile()
Expand Down