Skip to content

Commit

Permalink
Add an optional 'ASSHBinaryPath' variable in the 'assh.yml' file (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jun 6, 2016
1 parent 2366729 commit 0feb420
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
```
---
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func init() {
config.ASSHBinary = os.Args[0]
config.SetASSHBinaryPath(os.Args[0])
}

// Commands is the list of cli commands
Expand Down
17 changes: 16 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/moul/advanced-ssh-config/pkg/version"
)

var ASSHBinary = "assh"
var asshBinaryPath = "assh"

const defaultSshConfigPath string = "~/.ssh/config"

Expand All @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/config/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0feb420

Please sign in to comment.