@@ -31,6 +31,7 @@ func NewRootCommand() (cmd *cobra.Command) {
31
31
flags := cmd .Flags ()
32
32
flags .BoolVarP (& opt .loop , "loop" , "" , true , "Run the Markdown in loop mode." )
33
33
flags .BoolVarP (& opt .keepFilter , "keep-filter" , "" , true , "Indicate if keep the filter." )
34
+ flags .BoolVarP (& opt .keepScripts , "keep-scripts" , "" , false , "Indicate if keep the temporary scripts." )
34
35
return
35
36
}
36
37
@@ -75,6 +76,8 @@ func (o *option) runMarkdown(mdFilePath string) (err error) {
75
76
}
76
77
77
78
if content != "" && lang == "shell" {
79
+ originalContent := content
80
+
78
81
// handle the break line
79
82
breakline := regexp .MustCompile (`\\\n` )
80
83
content = breakline .ReplaceAllString (content , "" )
@@ -91,7 +94,15 @@ func (o *option) runMarkdown(mdFilePath string) (err error) {
91
94
continue
92
95
}
93
96
title = strings .TrimPrefix (title , "#!title: " )
94
- cmdMap [title ] = append (cmdMap [title ], lines [1 :]... )
97
+ // support multiple lines mode
98
+ if strings .Contains (title , "+f" ) {
99
+ title = strings .ReplaceAll (title , "+f" , "" )
100
+ title = strings .TrimSpace (title )
101
+
102
+ cmdMap [title ] = append (cmdMap [title ], originalContent )
103
+ } else {
104
+ cmdMap [title ] = append (cmdMap [title ], lines [1 :]... )
105
+ }
95
106
}
96
107
}
97
108
@@ -102,8 +113,9 @@ func (o *option) runMarkdown(mdFilePath string) (err error) {
102
113
}
103
114
104
115
type option struct {
105
- loop bool
106
- keepFilter bool
116
+ loop bool
117
+ keepFilter bool
118
+ keepScripts bool
107
119
}
108
120
109
121
func (o * option ) execute (cmdMap map [string ][]string , contextDir string ) (err error ) {
@@ -145,7 +157,7 @@ func (o *option) execute(cmdMap map[string][]string, contextDir string) (err err
145
157
continue
146
158
}
147
159
148
- err = runCmdLine (cmdLine , contextDir )
160
+ err = runCmdLine (cmdLine , contextDir , o . keepScripts )
149
161
if err != nil {
150
162
break
151
163
}
@@ -187,15 +199,17 @@ func inputRequest(pair []string) (result []string, err error) {
187
199
return
188
200
}
189
201
190
- func runCmdLine (cmdLine , contextDir string ) (err error ) {
202
+ func runCmdLine (cmdLine , contextDir string , keepScripts bool ) (err error ) {
191
203
var shellFile string
192
204
if shellFile , err = writeAsShell (cmdLine , contextDir ); err != nil {
193
205
fmt .Println (err )
194
206
return
195
207
}
196
- defer func () {
197
- _ = os .RemoveAll (shellFile )
198
- }()
208
+ if ! keepScripts {
209
+ defer func () {
210
+ _ = os .RemoveAll (shellFile )
211
+ }()
212
+ }
199
213
200
214
cmd := exec .Command ("bash" , path .Base (shellFile ))
201
215
cmd .Dir = contextDir
0 commit comments