Skip to content

Commit 54c7d75

Browse files
committed
fix config location
1 parent 7598017 commit 54c7d75

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ go get https://github.com/lixvbnet/sshw
4444

4545
## config
4646

47-
put config file `.sshw` or `.sshw.yml` in home directory or in the same directory of the binary.
47+
put config file `.sshw.yml` in home directory or in the same directory of the binary.
4848

4949
[config example](./sshlib/config_example.yml):
5050

sshlib/config.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import (
66
"golang.org/x/crypto/ssh"
77
"gopkg.in/yaml.v2"
88
"io/ioutil"
9+
"os"
910
"os/user"
1011
"path"
12+
"path/filepath"
1113
"strings"
1214
)
1315

@@ -162,9 +164,14 @@ func loadConfigBytes(filenames []string) (bytes []byte, err error) {
162164
return bytes, nil
163165
}
164166
}
165-
// relative
167+
// executable dir
168+
exe, err := os.Executable()
169+
if err != nil {
170+
return nil, err
171+
}
172+
exeDir := filepath.Dir(exe)
166173
for _, filename := range filenames {
167-
bytes, err = ioutil.ReadFile(filename)
174+
bytes, err = ioutil.ReadFile(path.Join(exeDir, filename))
168175
if err == nil {
169176
return bytes, nil
170177
}

0 commit comments

Comments
 (0)