diff options
author | Sascha Andres <sascha.andres@outlook.com> | 2018-09-10 10:31:15 +0200 |
---|---|---|
committer | Sascha Andres <sascha.andres@outlook.com> | 2018-09-10 10:31:15 +0200 |
commit | bb9698810d92dd1d59a0ee0e1ef192dee588036d (patch) | |
tree | 6073edf49f00c028e4f03241fd215bba073cf07f /pkg/commands/os.go | |
parent | 74144e3892253f72d703e3b324fb8459a0d45369 (diff) |
refactor: move fallback to platform struct
Co-authored-by: Jesse Duffield <jessedduffield@gmail.com>
Diffstat (limited to 'pkg/commands/os.go')
-rw-r--r-- | pkg/commands/os.go | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/pkg/commands/os.go b/pkg/commands/os.go index fd77f21c7..c8ca40f29 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -17,11 +17,12 @@ import ( // Platform stores the os state type Platform struct { - os string - shell string - shellArg string - escapedQuote string - openCommand string + os string + shell string + shellArg string + escapedQuote string + openCommand string + fallbackEscapedQuote string } // OSCommand holds all the os commands @@ -140,14 +141,11 @@ func (c *OSCommand) PrepareSubProcess(cmdName string, commandArgs ...string) *ex // Quote wraps a message in platform-specific quotation marks func (c *OSCommand) Quote(message string) string { message = strings.Replace(message, "`", "\\`", -1) - if c.Platform.os == "linux" { - if strings.ContainsRune(message, '\'') { - c.Platform.escapedQuote = `"` - } else { - c.Platform.escapedQuote = `'` - } + escapedQuote := c.Platform.escapedQuote + if strings.Contains(message, c.Platform.escapedQuote) { + escapedQuote = c.Platform.fallbackEscapedQuote } - return c.Platform.escapedQuote + message + c.Platform.escapedQuote + return escapedQuote + message + escapedQuote } // Unquote removes wrapping quotations marks if they are present |