Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copying committed file name crashes if running lazygit through ssh #1055

Open
karjonas opened this issue Oct 16, 2020 · 10 comments
Open

Copying committed file name crashes if running lazygit through ssh #1055

karjonas opened this issue Oct 16, 2020 · 10 comments
Labels
bug Something isn't working

Comments

@karjonas
Copy link

Describe the bug
Copying committed file name crashes if running lazygit through ssh.

To Reproduce
Steps to reproduce the behavior:

  1. Connect to a computer through ssh
  2. Run lazygit in a git repo
  3. Select a commit and a file name
  4. Click ctrl+o
  5. Crash

Expected behavior
The name of the committed name should be copied.

Desktop (please complete the following information):

  • OS: Arch Linux
  • Lazygit Version commit=d2ea5dd8b7fe62228854ad7f1a3a1d4681378b69, build date=2020-10-14T08:13:53Z, build source=binaryRelease, version=0.23.5, os=linux, arch=amd64|
@karjonas karjonas added the bug Something isn't working label Oct 16, 2020
@jesseduffield
Copy link
Owner

I'm not able to replicate this on mac. Do you have the stack trace handy?

@karjonas
Copy link
Author

karjonas commented Nov 28, 2020

I am now using this version:
commit=4b55b2e7fca96dcdf2a25c6d66e4545a4f184db1, build date=2020-11-10T09:06:27Z, build source=binaryRelease, version=0.23.7, os=linux, arch=amd64

stackTrace:

2020/11/28 12:44:27 An error occurred! Please create an issue at https://github.com/jesseduffield/lazygit/issues

*exec.ExitError exit status 1
github.com/jesseduffield/lazygit/main.go:133 (0x5579d34d0437)
runtime/proc.go:204 (0x5579d2f06609)
runtime/asm_amd64.s:1374 (0x5579d2f39a61)

@jesseduffield
Copy link
Owner

I wonder if the machine you've ssh'd onto lacks the required utilities to copy to clipboard. I also wonder how clipboard stuff generally works when dealing with ssh.

@mark2185
Copy link
Collaborator

mark2185 commented Aug 7, 2022

It requires xsel or something of sorts and that the ssh connection forwards X, which means one needs to connect with ssh -X <server>, as mentioned here. I guess this doesn't have to be a hard crash, but a helpful message?

@mestihudson
Copy link

It would be great if there had a custom config property to say to lazygit how to copy to the clipboard.
This way we could to define a command to, for example,

os:
  copyShaCommitToClipboard: ssh user@my-machine 'echo "${commit}" | pbcopy'

@redstreet
Copy link
Contributor

^ +1. OSC52 is my preferred way of copying. Would be great to have a config option to use this.

@jesseduffield
Copy link
Owner

This should be easy to implement, just a matter of going to pkg/commands/oscommands/os.go and updating the CopyToClipboard function to support a configured command

diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go
index 78dad7a8e..f51539a78 100644
--- a/pkg/commands/oscommands/os.go
+++ b/pkg/commands/oscommands/os.go
@@ -267,6 +267,14 @@ 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.CopyToClipboard != "" {
+		cmdStr := utils.ResolvePlaceholderString(c.UserConfig.OS.CopyToClipboard, map[string]string{
+			"text": c.Cmd.Quote(str),
+		})
+		return c.Cmd.NewShell(cmdStr).Run()
+	}
+
 	return clipboard.WriteAll(str)
 }

The CopyToClipboard key can be defined in pkg/config/user_config.go

Then it's a matter of updating the docs in docs/Config.md to add the os.copyToClipboard key.

I'll chuck a good-first-issue label on this. Do either of you want to take this on @mestihudson @redstreet ?

@redstreet
Copy link
Contributor

redstreet commented Jul 16, 2023

You pretty much included the whole code there (thank you!), and I wish I could do this, but I've never worked with Go, or with docker, so I'm unlikely to be able to find the time to set myself up adequately :(.

I'll offer this proposal instead, if someone else is interested in considering it:

Config wise, there could be two keys:

  • os.enableOsc52Clipboard = true/false key, which when set to true, would use this osc52 go library to copy
  • os.copyToClipboardCommand, when set, would run a custom command to copy to clipboard, and would ignore os.enableOsc52Clipboard

Update: the simpler solution is to include the command to do an OSC52 copy in the doc.

@redstreet
Copy link
Contributor

Just noticed the Github Codespaces in CONTRIBUTING. Cool. Let me take a shot at this.

redstreet added a commit to redstreet/lazygit that referenced this issue Jul 16, 2023
redstreet added a commit to redstreet/lazygit that referenced this issue Jul 16, 2023
redstreet added a commit to redstreet/lazygit that referenced this issue Jul 16, 2023
redstreet added a commit to redstreet/lazygit that referenced this issue Jul 17, 2023
redstreet added a commit to redstreet/lazygit that referenced this issue Jul 19, 2023
redstreet added a commit to redstreet/lazygit that referenced this issue Jul 20, 2023
Issue jesseduffield#1055

test: CopyPatchToClipboard (temporary commit for review)
redstreet added a commit to redstreet/lazygit that referenced this issue Jul 20, 2023
Issue jesseduffield#1055

test: CopyPatchToClipboard (temporary commit for review)
redstreet added a commit to redstreet/lazygit that referenced this issue Jul 20, 2023
Issue jesseduffield#1055

test: CopyPatchToClipboard (temporary commit for review)
redstreet added a commit to redstreet/lazygit that referenced this issue Jul 20, 2023
Issue jesseduffield#1055

test: CopyPatchToClipboard (temporary commit for review)
jesseduffield pushed a commit to redstreet/lazygit that referenced this issue Jul 29, 2023
Issue jesseduffield#1055

test: CopyPatchToClipboard (temporary commit for review)
jesseduffield pushed a commit to redstreet/lazygit that referenced this issue Jul 29, 2023
Issue jesseduffield#1055

test: CopyPatchToClipboard (temporary commit for review)
@mhanberg
Copy link

I am using a terminal emulator that supports OSC52, am SSHing into a computer and am inside of a tmux session.

The given example of using OSC52 doesn't seem to work, does anyone know why? I assume its something not related to lazygit, but just wondering if anyone else has ran into this.

My workaround is to use ssh, but that doesn't work when I'm actually on the computer

os:
  copyToClipboardCmd: "echo {{text}} | ssh \"mitchell@$(echo $SSH_CONNECTION | awk '{ print $1}')\" pbcopy"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants