feat: add os.copyToClipboardCmd to allow for a custom command

Issue #1055

test: CopyPatchToClipboard (temporary commit for review)
This commit is contained in:
Red S 2023-07-16 08:57:02 +00:00 committed by Jesse Duffield
parent 7e9f669421
commit d7f84aed8a
6 changed files with 70 additions and 50 deletions

View file

@ -267,6 +267,13 @@ func (c *OSCommand) CopyToClipboard(str string) error {
escaped := strings.Replace(str, "\n", "\\n", -1)
truncated := utils.TruncateWithEllipsis(escaped, 40)
c.LogCommand(fmt.Sprintf("Copying '%s' to clipboard", truncated), false)
if c.UserConfig.OS.CopyToClipboardCmd != "" {
cmdStr := utils.ResolvePlaceholderString(c.UserConfig.OS.CopyToClipboardCmd, map[string]string{
"text": c.Cmd.Quote(str),
})
return c.Cmd.NewShell(cmdStr).Run()
}
return clipboard.WriteAll(str)
}