Skip to content

Commit 81df133

Browse files
mamechksome
andcommitted
Add output format option
Fixes #10 Co-Authored-by: chksome <[email protected]>
1 parent c5c43af commit 81df133

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,28 @@ chmod 755 wsl2-ssh-agent
2222

2323
**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).**
2424

25-
### 2. Modify `.bashrc` (or `.zshrc` if you are using `zsh`)
25+
### 2. Modify your shell's rc file
26+
27+
#### bash or zsh
2628

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

2931
```
3032
eval $($HOME/wsl2-ssh-agent)
3133
```
3234

35+
#### fish
36+
37+
Add the following lines to `config.fish`
38+
39+
```
40+
if status is-login
41+
$HOME/wsl2-ssh-agent | source
42+
end
43+
```
44+
45+
### 3. Reopen your terminal
46+
3347
Close and reopen the terminal and execute `ssh your-machine`.
3448
The command should communicate with ssh-agent.exe service.
3549

config.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import (
1212
"os/exec"
1313
"os/signal"
1414
"path/filepath"
15+
"strings"
1516
"syscall"
1617
)
1718

1819
type config struct {
1920
socketPath string
2021
powershellPath string
22+
format string
2123
foreground bool
2224
verbose bool
2325
stop bool
@@ -76,6 +78,31 @@ func newConfig() *config {
7678
return c
7779
}
7880

81+
func getOutputFormat(format string) string {
82+
if format == "auto" {
83+
shell := os.Getenv("SHELL")
84+
if strings.HasSuffix(shell, "fish") {
85+
format = "fish"
86+
} else if strings.HasSuffix(shell, "csh") {
87+
format = "csh"
88+
} else {
89+
format = "sh"
90+
}
91+
}
92+
switch format {
93+
case "sh", "bash", "zsh":
94+
return "SSH_AUTH_SOCK=%s; export SSH_AUTH_SOCK;"
95+
case "csh", "tcsh":
96+
return "setenv SSH_AUTH_SOCK %s"
97+
case "fish":
98+
return "set -x SSH_AUTH_SOCK %s"
99+
default:
100+
fmt.Printf("output format must be auto, bash, zsh, csh, tcsh, or fish\n")
101+
os.Exit(1)
102+
return ""
103+
}
104+
}
105+
79106
func (c *config) start() context.Context {
80107
if c.version {
81108
fmt.Printf("wsl2-ssh-agent %s\n", version)
@@ -86,7 +113,7 @@ func (c *config) start() context.Context {
86113
parent := checkDaemonMode()
87114

88115
// script output
89-
output := fmt.Sprintf("SSH_AUTH_SOCK=%s; export SSH_AUTH_SOCK;", c.socketPath)
116+
output := fmt.Sprintf(getOutputFormat(c.format), c.socketPath)
90117

91118
// set up the log file
92119
c.setupLogFile()

0 commit comments

Comments
 (0)