feat: add os.copyToClipboardCmd to allow for a custom command #1055 (#2784)

This commit is contained in:
Jesse Duffield 2023-07-29 19:35:52 +10:00 committed by GitHub
commit f17417219a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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)
}