Skip to content

Commit

Permalink
Update instructions for using OSC52 with tmux (#3597)
Browse files Browse the repository at this point in the history
- **PR Description**
Update the instructions on using copyToClipboardCmd config to copy using
OSC52 with tmux

Added `-w 0` flag to `base64` command because it wraps lines that are
longer than 76 by default, [that fails to copy on some terminal
emulators](#3595).

We compare `$TERM` to `^(screen|tmux)` because both of them are valid as
[per the manual](https://man7.org/linux/man-pages/man1/tmux.1.html):
```
default-terminal terminal
               Set the default terminal for new windows created in this
               session - the default value of the TERM environment
               variable.  For to work correctly, this must be set to
               ‘screen’, ‘tmux’ or a derivative of them.
```

- **Please check if the PR fulfills these requirements**

* [x] Cheatsheets are up-to-date (run `go generate ./...`) -- not
relevant
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
-- not relevant
* [x] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide) -- not relevant
* [x] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
-- not relevant
* [x] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc

<!--
Be sure to name your PR with an imperative e.g. 'Add worktrees view'
see https://github.com/jesseduffield/lazygit/releases/tag/v0.40.0 for
examples
-->
  • Loading branch information
jesseduffield authored Jan 2, 2025
2 parents 6c6d835 + 69a048c commit fc69945
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -667,9 +667,26 @@ os:
Specify an external command to invoke when copying to clipboard is requested. `{{text}` will be replaced by text to be copied. Default is to copy to system clipboard.

If you are working on a terminal that supports OSC52, the following command will let you take advantage of it:
```yaml
os:
copyToClipboardCmd: printf "\033]52;c;$(printf {{text}} | base64 -w 0)\a" > /dev/tty
```

For tmux you need to wrap it with the [tmux escape sequence](https://github.com/tmux/tmux/wiki/FAQ#what-is-the-passthrough-escape-sequence-and-how-do-i-use-it), and enable passthrough in tmux config with `set -g allow-passthrough on`:
```yaml
os:
copyToClipboardCmd: printf "\033Ptmux;\033\033]52;c;$(printf {{text}} | base64 -w 0)\a\033\\" > /dev/tty
```

For the best of both worlds, we can let the command determine if we are running in a tmux session and send the correct sequence:
```yaml
os:
copyToClipboardCmd: printf "\033]52;c;$(printf {{text}} | base64)\a" > /dev/tty
copyToClipboardCmd: >
if [[ "$TERM" =~ ^(screen|tmux) ]]; then
printf "\033Ptmux;\033\033]52;c;$(printf {{text}} | base64 -w 0)\a\033\\" > /dev/tty
else
printf "\033]52;c;$(printf {{text}} | base64 -w 0)\a" > /dev/tty
fi
```

A custom command for reading from the clipboard can be set using
Expand Down

0 comments on commit fc69945

Please sign in to comment.