@@ -16,6 +16,17 @@ func getUnweaveSSHConfigPath() string {
1616 return filepath .Join (config .GetGlobalConfigPath (), "ssh_config" )
1717}
1818
19+ var sshDirPath = func () string {
20+ homeDir , err := os .UserHomeDir ()
21+ if err != nil {
22+ ui .Errorf ("Failed to get user home directory: %v" , err )
23+ os .Exit (1 )
24+ }
25+ return filepath .Join (homeDir , ".ssh" )
26+ }()
27+
28+ var sshConfigPath = filepath .Join (sshDirPath , "config" )
29+
1930func AddHost (alias , host , user string , port int , identityFile string ) error {
2031 configEntry := fmt .Sprintf (`Host %s
2132 HostName %s
@@ -43,13 +54,16 @@ func AddHost(alias, host, user string, port int, identityFile string) error {
4354 return err
4455 }
4556
46- home , err := os .UserHomeDir ()
57+ // Add an Include directive to the user's ssh config to unweave_global SSH configs - used for vscode-remote:
58+ err = os .MkdirAll (sshDirPath , 0700 )
4759 if err != nil {
48- ui .Errorf ("Failed to get user home directory: %v" , err )
49- os .Exit (1 )
60+ fmt .Println ("Failed to create .ssh folder:" , err )
61+ }
62+ if _ , err := os .Stat (sshConfigPath ); os .IsNotExist (err ) {
63+ if _ , err = os .Create (sshConfigPath ); err != nil {
64+ return err
65+ }
5066 }
51- sshConfigPath := filepath .Join (home , ".ssh" , "config" )
52-
5367 lines , err := readLines (sshConfigPath )
5468 if err != nil {
5569 return err
0 commit comments