@@ -41,7 +41,7 @@ func (i *Item) Action() ActionFunc {
4141 actions = append (actions , actionHref (debugf , i .Params .Href ))
4242 }
4343 if i .Params .Shell != "" {
44- actions = append (actions , actionShell (debugf , i , i .Params .Shell , i .Params .ShellParams , i .Plugin .Variables ))
44+ actions = append (actions , actionShell (debugf , i , i .Plugin . AppleScriptTemplate , i . Params .Shell , i .Params .ShellParams , i .Plugin .Variables ))
4545 }
4646 if i .Params .Refresh {
4747 shouldDelayBeforeRefresh := false
@@ -115,24 +115,15 @@ func actionHref(debugf DebugFunc, href string) ActionFunc {
115115}
116116
117117// actionShell gets an ActionFunc that runs a shell command.
118- func actionShell (debugf DebugFunc , item * Item , command string , params , envVars []string ) ActionFunc {
118+ func actionShell (debugf DebugFunc , item * Item , appleScriptTemplate , command string , params , envVars []string ) ActionFunc {
119119 if item .Params .Terminal {
120- return actionShellTerminal (debugf , item , command , params , envVars )
120+ return actionShellTerminal (debugf , item , appleScriptTemplate , command , params , envVars )
121121 }
122122 return func (ctx context.Context ) {
123123 var commandExec string
124124 var commandArgs []string
125- // if item.Params.Terminal {
126- // shell := os.Getenv("SHELL")
127- // if shell == "" {
128- // shell = "/bin/bash"
129- // }
130- // commandExec = shell
131- // commandArgs = append([]string{command}, params...)
132- // } else {
133125 commandExec = command
134126 commandArgs = params
135- //}
136127 debugf ("exec: %s %s" , commandExec , strings .Join (commandArgs , " " ))
137128 cmd := exec .CommandContext (context .Background (), commandExec , commandArgs ... )
138129 cmd .SysProcAttr = & syscall.SysProcAttr {
@@ -156,30 +147,17 @@ func actionShell(debugf DebugFunc, item *Item, command string, params, envVars [
156147}
157148
158149// actionShellTerminal runs shell commands where terminal=true.
159- func actionShellTerminal (debugf DebugFunc , item * Item , command string , params , envVars []string ) ActionFunc {
150+ func actionShellTerminal (debugf DebugFunc , item * Item , appleScriptTemplate , command string , params , envVars []string ) ActionFunc {
160151 return func (ctx context.Context ) {
161152 debugf ("exec: RunInTerminal..." )
162- script := `
163- activate application "Terminal"
164- tell application "Terminal"
165- if not (exists window 1) then reopen
166- set quotedScriptName to quoted form of "{{ .Command }}"
167- {{ if .Params }}
168- set commandLine to {{ .Vars }} & " " & quotedScriptName & " " & {{ .Params }}
169- {{ else }}
170- set commandLine to {{ .Vars }} & " " & quotedScriptName
171- {{ end }}
172- do script commandLine
173- end tell
174- `
175153 command := strconv .Quote (command )
176154 command = command [1 : len (command )- 1 ] // trim quotes off
177155 for i := range params {
178156 params [i ] = strconv .Quote (params [i ])
179157 params [i ] = params [i ][1 : len (params [i ])- 1 ] // trim quotes off
180158 }
181159 paramsStr := strconv .Quote (strings .Join (params , " " ))
182- err := item .Plugin .runInTerminal (script , command , paramsStr , envVars )
160+ err := item .Plugin .runInTerminal (appleScriptTemplate , command , paramsStr , envVars )
183161 if err != nil {
184162 debugf ("exec: RunInTerminal: err=%s" , err )
185163 return
0 commit comments