@@ -5,122 +5,123 @@ import (
5
5
"github.com/davfive/gitspaces/v2/internal/utils"
6
6
)
7
7
8
- // RunUserEnvironmentCheck() runs a series of checks to ensure the user's environment
8
+ func ForceUserEnvironmentSetup () {
9
+ console .Println ("============================" )
10
+ console .Println ("== GitSpaces Setup Wizard ==" )
11
+ console .Println ("============================" )
12
+ runUserEnvironmentChecks (true )
13
+ }
14
+
15
+ func RunUserEnvironmentChecks () bool {
16
+ return runUserEnvironmentChecks (false )
17
+ }
18
+
19
+ // runUserEnvironmentChecks() runs a series of checks to ensure the user's environment
9
20
// is properly configured for GitSpaces. Returns true if any checks failed.
10
21
// When a check fails, the user is prompted to update their environment. Once that is
11
22
// done, the user would be able to run the gitspaces command again successfully
12
- func RunUserEnvironmentCheck ( ) (checkFailed bool ) {
23
+ func runUserEnvironmentChecks ( force bool ) (checkFailed bool ) {
13
24
shellUpdated := false
14
25
15
- if runProjectPathsCheck () == true {
26
+ if runProjectPathsCheck (force ) == true {
16
27
checkFailed = true
17
28
}
18
- if runShellWrapperCheck () == true {
29
+ if runShellWrapperCheck (force ) == true {
19
30
shellUpdated = true
20
31
checkFailed = true
21
32
}
22
33
23
34
if checkFailed {
24
- console .Println ("\n You are ready to use GitSpaces (assuming you followed the instructions)." )
35
+ console .Println ("\n See https://github.com/davfive/gitspaces README for full setup and use instructions." )
36
+ console .Println ("You are ready to use GitSpaces (assuming you followed the instructions)." )
25
37
if shellUpdated {
26
- console .Println ("Open a new shell and rerun 'gitspaces' (the shell wrapper) to start using GitSpaces." )
38
+ console .Println ("Open a new shell and run 'gitspaces' (the shell wrapper) to start using GitSpaces." )
27
39
} else {
28
- console .Println ("Rerun 'gitspaces' (the shell wrapper) to start using GitSpaces." )
40
+ console .Println ("Run 'gitspaces' (the shell wrapper) to start using GitSpaces." )
29
41
}
30
42
}
31
43
return checkFailed
32
44
}
33
45
34
46
// runProjectPathsCheck() prompts the user to set project paths in the config file
35
47
// if they are not already set. Returns true if user asked to update paths.
36
- func runProjectPathsCheck () bool {
37
- if len (User .projectPaths ) > 0 {
48
+ func runProjectPathsCheck (force bool ) bool {
49
+ if ! force && len (User .projectPaths ) > 0 {
38
50
return false
39
51
}
40
52
41
- console .Println ("** Warning - Empty ProjectPaths found in %s **\n " , User .GetConfigFile ())
42
- console .Println ("GitSpaces uses the ProjectPaths field to know where to find your projects" )
43
- console .Println ("Fill in the ProjectPaths in your config file with something like:" )
53
+ console .PrintSeparateln ("== Setup GitSpaces ProjectPaths" )
54
+ console .Println ("GitSpaces uses the ProjectPaths field to know where to find your projects." )
55
+ console .Println ("" )
56
+ console .Println ("Fill in the ProjectPaths in the GitSpaces config file with something like:" )
44
57
console .Println ("ProjectPaths:" )
45
- console .Println (" - {{.HomeDir}}/code/projects" )
46
- console .Println (" - {{.HomeDir}}/code/play" )
58
+ console .Println (" - %s/code/projects" , utils .GetUserHomeDir ())
59
+ console .Println (" - %s/code/play" , utils .GetUserHomeDir ())
60
+ console .Println ("" )
61
+ console .Println ("The config file is located at: %s" , User .GetConfigFile ())
47
62
console .Println ("" )
48
63
49
64
if console .NewConfirm ().Prompt ("Edit config file?" ).Run () == true {
50
65
if err := utils .OpenFileInDefaultApp (User .GetConfigFile ()); err != nil {
51
66
console .Errorln ("Editing config file failed: %s" , err )
67
+ } else {
68
+ console .NewInput ().Prompt ("Press <enter> when done editing the file ..." ).Run ()
52
69
}
53
70
}
54
71
return true
55
72
}
56
73
57
74
// runProjectPathsCheck() prompts the user to set project paths in the config file
58
75
// if they are not already set. Returns true if user asked to update paths.
59
- func runShellWrapperCheck () bool {
60
- if User .wrapped {
76
+ func runShellWrapperCheck (force bool ) bool {
77
+ if ! force && User .wrapped {
61
78
return false
62
79
}
63
80
64
- console .Println ( "** Warning - GitSpaces not run from shell wrapper ** \n " )
81
+ console .PrintSeparateln ( "== Setup GitSpaces Shell Wrapper " )
65
82
console .Println ("GitSpaces requires a wrapper function in your shell profile/rc file." )
66
83
console .Println ("The wrapper handles when a 'gitspaces <command>' needs to 'cd' to a new directory." )
67
- console .Println ("\n Wrappers are available for common shells (bash, zsh, pwsh)." )
68
- console .Println ("See https://github.com/davfive/gitspaces README for all setup instructions." )
69
84
console .Println ("" )
70
85
86
+ if ! User .wrapped {
87
+ console .Println ("** Warning - GitSpaces not run from shell wrapper **\n " )
88
+ }
89
+
90
+ shellFiles := GetShellFiles ()
71
91
if Debug {
72
- shellFiles := GetShellFiles ()
73
92
console .Println ("The following wrapper files were created:" )
74
93
for _ , key := range utils .SortKeys (shellFiles ) {
75
94
console .Println (" %s" , shellFiles [key ].path )
76
95
}
77
96
console .Println ("" )
78
97
}
79
98
80
- if User .pterm != "" {
81
- console .Println ("Your current shell is: %s" , User .pterm )
99
+ console .Println ("Shell Wrapper Setup Instructions:" )
100
+ console .Println ("1. Copy the following lines:" )
101
+ if User .pterm == "pwsh" {
102
+ console .Println (". %s" , shellFiles ["ps1ScriptBlock" ].path )
103
+ console .Println ("Set-Alias -Name gs -Value gitspaces # optional" )
104
+ } else {
105
+ console .Println (". %s" , shellFiles ["shellFunction" ].path )
106
+ console .Println ("alias gs=gitspaces" )
82
107
}
83
- if console .NewConfirm ().Prompt ("Would you like to configure it now?" ).Run () == true {
84
- switch User .pterm {
85
- case "bash" , "zsh" :
86
- setupBashZshWrapper ()
87
- case "pwsh" :
88
- setupPwshWrapper ()
89
- default :
90
- console .Println ("Unable to determine your current shell rc file. Assuming *nix-style." )
91
- console .Println ("Copy/paste these lines into your shell's rc file:" )
92
- console .Println (". %s/gitspaces.sh" , utils .CygwinizePath (User .dotDir ))
93
- console .Println ("alias gs=gitspaces" )
94
- }
95
- }
96
-
97
- return true
98
- }
108
+ console .Println ("2. Paste the lines into your shell profile or rc file." )
109
+ console .Println ("3. Open a new shell and run 'gitspaces' to start using GitSpaces." )
99
110
100
- func setupBashZshWrapper () {
101
- shellrc := User .getShellRcFile ()
102
- console .Println ("Copy/paste these lines into your shell's rc file:" )
103
- console .Println (". %s/gitspaces.sh" , utils .CygwinizePath (User .dotDir ))
104
- console .Println ("alias gs=gitspaces" )
105
- console .Println ("\n Your shell rc file is located at: %s" , shellrc )
106
- if console .NewConfirm ().Prompt ("Edit shell rc file?" ).Run () == true {
107
- if err := utils .OpenFileInDefaultApp (shellrc ); err != nil {
108
- console .Errorln ("Editing shell rc file failed: %s" , err )
111
+ if User .pterm != "" {
112
+ shellRcFile := User .getShellRcFile ()
113
+ console .Println ("\n Your current shell is: %s" , User .pterm )
114
+ console .Println ("Your shell profile/rc file is located at: %s" , shellRcFile )
115
+ console .Println ("" )
116
+ if console .NewConfirm ().Prompt ("Edit %s?" , shellRcFile ).Run () == true {
117
+ utils .CreateEmptyFileIfNotExists (shellRcFile )
118
+ if err := utils .OpenFileInDefaultApp (shellRcFile ); err != nil {
119
+ console .Errorln ("Editing shell rc file failed: %s" , err )
120
+ } else {
121
+ console .NewInput ().Prompt ("Press <enter> when done editing the file ..." ).Run ()
122
+ }
109
123
}
110
124
}
111
- }
112
125
113
- func setupPwshWrapper () {
114
- shellFiles := GetShellFiles ()
115
- shellrc := User .getShellRcFile ()
116
- console .Println ("Copy/paste these lines into your PowerShell $PROFILE file:" )
117
- console .Println (". %s" , shellFiles ["ps1ScriptBlock" ].path )
118
- console .Println ("Set-Alias -Name gs -Value gitspaces # optional" )
119
- console .Println ("\n Your PowerShell profile is located at: %s" , shellrc )
120
- // console.Println("For more information on your PowerShell profile, see https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.4#the-profile-variable")
121
- if console .NewConfirm ().Prompt ("Edit PowerShell $PROFILE?" ).Run () == true {
122
- if err := utils .OpenFileInDefaultApp (shellrc ); err != nil {
123
- console .Errorln ("Editing PowerShell $PROFILE failed: %s" , err )
124
- }
125
- }
126
+ return true
126
127
}
0 commit comments