mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-31 14:24:25 +03:00
Add function os.PasteFromClipboard
And a user config to override it with a custom command.
This commit is contained in:
@ -415,9 +415,13 @@ os:
|
|||||||
openLinkCommand: ""
|
openLinkCommand: ""
|
||||||
|
|
||||||
# CopyToClipboardCmd is the command for copying to clipboard.
|
# CopyToClipboardCmd is the command for copying to clipboard.
|
||||||
# See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-command-for-copying-to-clipboard
|
# See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-command-for-copying-to-and-pasting-from-clipboard
|
||||||
copyToClipboardCmd: ""
|
copyToClipboardCmd: ""
|
||||||
|
|
||||||
|
# ReadFromClipboardCmd is the command for reading the clipboard.
|
||||||
|
# See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-command-for-copying-to-and-pasting-from-clipboard
|
||||||
|
readFromClipboardCmd: ""
|
||||||
|
|
||||||
# If true, don't display introductory popups upon opening Lazygit.
|
# If true, don't display introductory popups upon opening Lazygit.
|
||||||
disableStartupPopups: false
|
disableStartupPopups: false
|
||||||
|
|
||||||
@ -620,7 +624,7 @@ os:
|
|||||||
open: 'open {{filename}}'
|
open: 'open {{filename}}'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Custom Command for Copying to Clipboard
|
## Custom Command for Copying to and Pasting from Clipboard
|
||||||
```yaml
|
```yaml
|
||||||
os:
|
os:
|
||||||
copyToClipboardCmd: ''
|
copyToClipboardCmd: ''
|
||||||
@ -633,6 +637,12 @@ os:
|
|||||||
copyToClipboardCmd: printf "\033]52;c;$(printf {{text}} | base64)\a" > /dev/tty
|
copyToClipboardCmd: printf "\033]52;c;$(printf {{text}} | base64)\a" > /dev/tty
|
||||||
```
|
```
|
||||||
|
|
||||||
|
A custom command for reading from the clipboard can be set using
|
||||||
|
```yaml
|
||||||
|
os:
|
||||||
|
readFromClipboardCmd: ''
|
||||||
|
```
|
||||||
|
It is used, for example, when pasting a commit message into the commit message panel. The command is supposed to output the clipboard content to stdout.
|
||||||
|
|
||||||
## Configuring File Editing
|
## Configuring File Editing
|
||||||
|
|
||||||
|
@ -302,6 +302,23 @@ func (c *OSCommand) CopyToClipboard(str string) error {
|
|||||||
return clipboard.WriteAll(str)
|
return clipboard.WriteAll(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *OSCommand) PasteFromClipboard() (string, error) {
|
||||||
|
var s string
|
||||||
|
var err error
|
||||||
|
if c.UserConfig.OS.CopyToClipboardCmd != "" {
|
||||||
|
cmdStr := c.UserConfig.OS.ReadFromClipboardCmd
|
||||||
|
s, err = c.Cmd.NewShell(cmdStr).RunWithOutput()
|
||||||
|
} else {
|
||||||
|
s, err = clipboard.ReadAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.ReplaceAll(s, "\r\n", "\n"), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *OSCommand) RemoveFile(path string) error {
|
func (c *OSCommand) RemoveFile(path string) error {
|
||||||
msg := utils.ResolvePlaceholderString(
|
msg := utils.ResolvePlaceholderString(
|
||||||
c.Tr.Log.RemoveFile,
|
c.Tr.Log.RemoveFile,
|
||||||
|
@ -565,8 +565,12 @@ type OSConfig struct {
|
|||||||
OpenLinkCommand string `yaml:"openLinkCommand,omitempty"`
|
OpenLinkCommand string `yaml:"openLinkCommand,omitempty"`
|
||||||
|
|
||||||
// CopyToClipboardCmd is the command for copying to clipboard.
|
// CopyToClipboardCmd is the command for copying to clipboard.
|
||||||
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-command-for-copying-to-clipboard
|
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-command-for-copying-to-and-pasting-from-clipboard
|
||||||
CopyToClipboardCmd string `yaml:"copyToClipboardCmd,omitempty"`
|
CopyToClipboardCmd string `yaml:"copyToClipboardCmd,omitempty"`
|
||||||
|
|
||||||
|
// ReadFromClipboardCmd is the command for reading the clipboard.
|
||||||
|
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-command-for-copying-to-and-pasting-from-clipboard
|
||||||
|
ReadFromClipboardCmd string `yaml:"readFromClipboardCmd,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomCommandAfterHook struct {
|
type CustomCommandAfterHook struct {
|
||||||
|
@ -796,7 +796,11 @@
|
|||||||
},
|
},
|
||||||
"copyToClipboardCmd": {
|
"copyToClipboardCmd": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "CopyToClipboardCmd is the command for copying to clipboard.\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-command-for-copying-to-clipboard"
|
"description": "CopyToClipboardCmd is the command for copying to clipboard.\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-command-for-copying-to-and-pasting-from-clipboard"
|
||||||
|
},
|
||||||
|
"readFromClipboardCmd": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "ReadFromClipboardCmd is the command for reading the clipboard.\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-command-for-copying-to-and-pasting-from-clipboard"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
Reference in New Issue
Block a user