fuzzyworld

template / commit

Using pwsh for executing post script and some VSCode stuff.

1bfa421a778a507851218fc0e29454185d448d17 · Pavel Safronov · 2022-09-23 00:35:09 -0700 · parents bfbd125cb989

Using pwsh for executing post script and some VSCode stuff.
 .vscode/launch.json | 2 +-
 config.go           | 4 ++++
 new.go              | 5 +++--
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/.vscode/launch.json b/.vscode/launch.json
index 8ed2713..4edb528 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -8,7 +8,7 @@
             "name": "Delete ~/.template.yaml",
             "type": "PowerShell",
             "request": "launch",
-            "script": "rm ~/.template.yaml -ErrorAction SilentlyContinue",
+            "script": "Remote-Item ~/.template.yaml -ErrorAction SilentlyContinue",
             "cwd": "${workspaceFolder}"
         },
         {
diff --git a/config.go b/config.go
index b1991e9..f1016bb 100644
--- a/config.go
+++ b/config.go
@@ -19,6 +19,7 @@ type Profile struct {
 	Type         ProfileType
 	NamePatterns []string
 	PostScript   []string
+	ScriptShell  string
 
 	// FileTemplatePath string
 }
@@ -40,6 +41,7 @@ func defaultConfig() Config {
 						"{{if (gt $index 0)}}-{{$index}}{{end}}" +
 						".md",
 				},
+				ScriptShell: "pwsh",
 				PostScript: []string{
 					"code",
 					".",
@@ -56,6 +58,7 @@ func defaultConfig() Config {
 						"{{if .ProjectName}}-{{.ProjectName}}{{end}}" +
 						".md",
 				},
+				ScriptShell: "pwsh",
 				PostScript: []string{
 					"code",
 					".",
@@ -71,6 +74,7 @@ func defaultConfig() Config {
 					"{{.Year}}-{{.Month}}-{{.Day}}-{{.Hour}}-{{.Minute}}{{if .ProjectName}}-{{.ProjectName}}{{end}}",
 					"{{.Year}}-{{.Month}}-{{.Day}}-{{.Hour}}-{{.Minute}}-{{.Second}}{{if .ProjectName}}-{{.ProjectName}}{{end}}",
 				},
+				ScriptShell: "pwsh",
 				PostScript: []string{
 					"explorer",
 					"{{.Path}}",
diff --git a/new.go b/new.go
index 4033292..385a544 100644
--- a/new.go
+++ b/new.go
@@ -103,9 +103,10 @@ func processProfile(profile Profile, name string) error {
 	if postScripts != nil && len(postScripts) > 0 {
 		allArgs := []string{"/C"}
 		allArgs = append(allArgs, postScripts...)
-		debugProfileScript := fmt.Sprintf("cmd %v", strings.Trim(fmt.Sprint(allArgs), "[]"))
+		shell := profile.ScriptShell
+		debugProfileScript := fmt.Sprintf("%v %v", shell, strings.Trim(fmt.Sprint(allArgs), "[]"))
 		fmt.Printf("Executing post script: %v \n", debugProfileScript)
-		cmd := exec.Command("cmd", allArgs...)
+		cmd := exec.Command(shell, allArgs...)
 		if err := cmd.Run(); err != nil {
 			// post scripts tend to fail (TODO: investigate why), so for now we'll just log the error
 			fmt.Printf("Error executing post script '%v': %v\n", debugProfileScript, err)