From 95cb1b252027d784d99785e134556cb986584c4f Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Tue, 2 May 2017 23:04:59 +0200 Subject: [PATCH] Generate full assh binary path in ~/.ssh/config (fix #148) --- README.md | 1 + pkg/commands/commands.go | 12 +++++++++++- pkg/config/config.go | 2 ++ pkg/config/host.go | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index aba602f94..8a1648e40 100644 --- a/README.md +++ b/README.md @@ -824,6 +824,7 @@ Host * * Add RateLimit support ([#65](https://github.com/moul/advanced-ssh-config/issues/65)) * Add possibility to disable automatic configuration rewrite ([#239](https://github.com/moul/advanced-ssh-config/issues/239)) * Add `BeforeConfigWrite` and `AfterConfigWrite` new hooks ([#239](https://github.com/moul/advanced-ssh-config/issues/239)) +* Generate full assh binary path in ~/.ssh/config ([#148](https://github.com/moul/advanced-ssh-config/issues/148)) [Full commits list](https://github.com/moul/advanced-ssh-config/compare/v2.6.0...master) diff --git a/pkg/commands/commands.go b/pkg/commands/commands.go index 196df1399..f749e7a77 100644 --- a/pkg/commands/commands.go +++ b/pkg/commands/commands.go @@ -1,7 +1,9 @@ package commands import ( + "log" "os" + "path/filepath" "github.com/moul/advanced-ssh-config/pkg/config" "github.com/urfave/cli" @@ -9,7 +11,15 @@ import ( ) func init() { - config.SetASSHBinaryPath(os.Args[0]) + ex, err := os.Executable() + if err != nil { + log.Fatal(err) + } + abspath, err := filepath.Abs(ex) + if err != nil { + log.Fatal(err) + } + config.SetASSHBinaryPath(abspath) } // Commands is the list of cli commands diff --git a/pkg/config/config.go b/pkg/config/config.go index aafe08054..ce510c9f6 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "io/ioutil" + "log" "os" "path" "path/filepath" @@ -44,6 +45,7 @@ func (c *Config) DisableAutomaticRewrite() { // SetASSHBinaryPath sets the default assh binary path // this value may be overwritten in the assh.yml file using the asshbinarypath variable func SetASSHBinaryPath(path string) { + log.Println(path) asshBinaryPath = path } diff --git a/pkg/config/host.go b/pkg/config/host.go index 3b054d3da..f37321b0e 100644 --- a/pkg/config/host.go +++ b/pkg/config/host.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "io" + "log" "os/user" "strings" @@ -1378,6 +1379,7 @@ func (h *Host) WriteSSHConfigTo(w io.Writer) error { // ssh-config fields with a different behavior if h.isDefault { + log.Println(asshBinaryPath) if h.noAutomaticRewrite { fmt.Fprintf(w, " ProxyCommand %s connect --no-rewrite --port=%%p %%h\n", asshBinaryPath) } else {