diff --git a/README.md b/README.md index 27261f9..3555daa 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ go get https://github.com/lixvbnet/sshw ## config -put config file `.sshw` or `.sshw.yml` in home directory or in the same directory of the binary. +put config file `.sshw.yml` in home directory or in the same directory of the binary. [config example](./sshlib/config_example.yml): diff --git a/sshlib/config.go b/sshlib/config.go index 88460d5..4d494d5 100644 --- a/sshlib/config.go +++ b/sshlib/config.go @@ -6,8 +6,10 @@ import ( "golang.org/x/crypto/ssh" "gopkg.in/yaml.v2" "io/ioutil" + "os" "os/user" "path" + "path/filepath" "strings" ) @@ -162,9 +164,14 @@ func loadConfigBytes(filenames []string) (bytes []byte, err error) { return bytes, nil } } - // relative + // executable dir + exe, err := os.Executable() + if err != nil { + return nil, err + } + exeDir := filepath.Dir(exe) for _, filename := range filenames { - bytes, err = ioutil.ReadFile(filename) + bytes, err = ioutil.ReadFile(path.Join(exeDir, filename)) if err == nil { return bytes, nil }