diff --git a/README.md b/README.md index 3773ee939..afd29529e 100644 --- a/README.md +++ b/README.md @@ -112,17 +112,17 @@ Let's consider the following `assh.yml` file hosts: hosta: Hostname: 1.2.3.4 - + hostb: Hostname: 5.6.7.8 Gateways: - hosta - + hostc: Hostname: 9.10.11.12 Gateways: - hostb - + hostd: Hostname: 13.14.15.16 Gateways: @@ -278,6 +278,8 @@ includes: - ~/.ssh/assh.d/*.yml - /etc/assh.yml - $ENV_VAR/blah-blah-*/*.yml + +ASSHBinaryPath: ~/bin/assh # optionally set the path of assh ``` --- @@ -376,7 +378,7 @@ With the wrapper, `ssh` will *always* be called with an updated `~/.ssh/config` ### master (unreleased) -* No entry +* Add an optional `ASSHBinaryPath` variable in the `assh.yml` file ([#148](https://github.com/moul/advanced-ssh-config/issues/148)) [Full commits list](https://github.com/moul/advanced-ssh-config/compare/v2.3.0...master) diff --git a/pkg/commands/commands.go b/pkg/commands/commands.go index 864895c18..553c937d6 100644 --- a/pkg/commands/commands.go +++ b/pkg/commands/commands.go @@ -10,7 +10,7 @@ import ( ) func init() { - config.ASSHBinary = os.Args[0] + config.SetASSHBinaryPath(os.Args[0]) } // Commands is the list of cli commands diff --git a/pkg/config/config.go b/pkg/config/config.go index a9c1c3884..6fefa8b48 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -18,7 +18,7 @@ import ( "github.com/moul/advanced-ssh-config/pkg/version" ) -var ASSHBinary = "assh" +var asshBinaryPath = "assh" const defaultSshConfigPath string = "~/.ssh/config" @@ -29,11 +29,18 @@ type Config struct { Defaults Host `yaml:"defaults,omitempty,flow" json:"defaults,omitempty"` Includes []string `yaml:"includes,omitempty,flow" json:"includes,omitempty"` ASSHKnownHostFile string `yaml:"asshknownhostfile,omitempty,flow" json:"asshknownhostfile,omitempty"` + ASSHBinaryPath string `yaml:"asshbinarypath,omitempty,flow" json:"asshbinarypath,omitempty"` includedFiles map[string]bool sshConfigPath string } +// 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) { + asshBinaryPath = path +} + // SaveNewKnownHost registers the target as a new known host and save the full known hosts list on disk func (c *Config) SaveNewKnownHost(target string) { c.addKnownHost(target) @@ -448,6 +455,13 @@ func (c *Config) LoadFiles(pattern string) error { } } + if c.ASSHBinaryPath != "" { + path, err := expandUser(c.ASSHBinaryPath) + if err != nil { + return err + } + asshBinaryPath = path + } return nil } @@ -501,6 +515,7 @@ func New() *Config { config.includedFiles = make(map[string]bool) config.sshConfigPath = defaultSshConfigPath config.ASSHKnownHostFile = "~/.ssh/assh_known_hosts" + config.ASSHBinaryPath = "" return &config } diff --git a/pkg/config/host.go b/pkg/config/host.go index 0dc2259e7..e84ed58e5 100644 --- a/pkg/config/host.go +++ b/pkg/config/host.go @@ -936,7 +936,7 @@ func (h *Host) WriteSSHConfigTo(w io.Writer) error { // ssh-config fields with a different behavior if h.isDefault { - fmt.Fprintf(w, " ProxyCommand %s proxy --port=%%p %%h\n", ASSHBinary) + fmt.Fprintf(w, " ProxyCommand %s proxy --port=%%p %%h\n", asshBinaryPath) } else { if h.ProxyCommand != "" { fmt.Fprintf(w, " # ProxyCommand %s\n", h.ProxyCommand)