Skip to content

Commit

Permalink
fix config location
Browse files Browse the repository at this point in the history
  • Loading branch information
lixvbnet committed Dec 31, 2021
1 parent 7598017 commit 54c7d75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
11 changes: 9 additions & 2 deletions sshlib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"golang.org/x/crypto/ssh"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"os/user"
"path"
"path/filepath"
"strings"
)

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

0 comments on commit 54c7d75

Please sign in to comment.