Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,8 @@ func NewInclude(directives []string, hasEquals bool, pos Position, comment strin
path = directives[i]
} else if system {
path = filepath.Join("/etc/ssh", directives[i])
} else if strings.HasPrefix(directives[i], "~/") {
path = filepath.Join(homedir(), directives[i][2:])
} else {
path = filepath.Join(homedir(), ".ssh", directives[i])
}
Expand Down
26 changes: 26 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,32 @@ func TestIncludeString(t *testing.T) {
}
}

var shellIncludeFile = []byte(`
# This host should not exist, so we can use it for test purposes / it won't
# interfere with any other configurations.
Host kevinburke.ssh_config.test.example.com
Port 4567
`)

func TestIncludeShellHomeDirectory(t *testing.T) {
if testing.Short() {
t.Skip("skipping fs write in short mode")
}
testPath := filepath.Join(homedir(), "kevinburke-ssh-config-shell-include")
err := ioutil.WriteFile(testPath, shellIncludeFile, 0644)
if err != nil {
t.Skipf("couldn't write SSH config file: %v", err.Error())
}
defer os.Remove(testPath)
us := &UserSettings{
userConfigFinder: testConfigFinder("testdata/include-shell"),
}
val := us.Get("kevinburke.ssh_config.test.example.com", "Port")
if val != "4567" {
t.Errorf("expected to find Port=4567 in included file, got %q", val)
}
}

var matchTests = []struct {
in []string
alias string
Expand Down
2 changes: 2 additions & 0 deletions testdata/include-shell
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Host kevinburke.ssh_config.test.example.com
Include ~/kevinburke-ssh-config-shell-include