mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-19 12:12:42 +02:00
Extract helper function quotedCommandString
Will be reused in the next commit.
This commit is contained in:
parent
da94ee7a9a
commit
39e77d1823
@ -43,10 +43,16 @@ func (self *CmdObjBuilder) NewWithEnviron(args []string, env []string) ICmdObj {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *CmdObjBuilder) NewShell(commandStr string) ICmdObj {
|
func (self *CmdObjBuilder) NewShell(commandStr string) ICmdObj {
|
||||||
var quotedCommand string
|
quotedCommand := self.quotedCommandString(commandStr)
|
||||||
|
cmdArgs := str.ToArgv(fmt.Sprintf("%s %s %s", self.platform.Shell, self.platform.ShellArg, quotedCommand))
|
||||||
|
|
||||||
|
return self.New(cmdArgs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *CmdObjBuilder) quotedCommandString(commandStr string) string {
|
||||||
// Windows does not seem to like quotes around the command
|
// Windows does not seem to like quotes around the command
|
||||||
if self.platform.OS == "windows" {
|
if self.platform.OS == "windows" {
|
||||||
quotedCommand = strings.NewReplacer(
|
return strings.NewReplacer(
|
||||||
"^", "^^",
|
"^", "^^",
|
||||||
"&", "^&",
|
"&", "^&",
|
||||||
"|", "^|",
|
"|", "^|",
|
||||||
@ -54,13 +60,9 @@ func (self *CmdObjBuilder) NewShell(commandStr string) ICmdObj {
|
|||||||
">", "^>",
|
">", "^>",
|
||||||
"%", "^%",
|
"%", "^%",
|
||||||
).Replace(commandStr)
|
).Replace(commandStr)
|
||||||
} else {
|
|
||||||
quotedCommand = self.Quote(commandStr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdArgs := str.ToArgv(fmt.Sprintf("%s %s %s", self.platform.Shell, self.platform.ShellArg, quotedCommand))
|
return self.Quote(commandStr)
|
||||||
|
|
||||||
return self.New(cmdArgs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CmdObjBuilder) CloneWithNewRunner(decorate func(ICmdObjRunner) ICmdObjRunner) *CmdObjBuilder {
|
func (self *CmdObjBuilder) CloneWithNewRunner(decorate func(ICmdObjRunner) ICmdObjRunner) *CmdObjBuilder {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user