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

add(tmux): copy support for linux #167

Closed
wants to merge 1 commit into from
Closed

add(tmux): copy support for linux #167

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Dec 10, 2020

As I couldn't test in mac I've left your commands the same but you can see here that there's no longer a need for reattach-to-user-namespace. You have to test if it works just with pbcopy alone.

An useful addition that I haven't included is that selection with mouse should copy to clipboard right away, in addition to the default action. In linux it's done with:

bind -T copy-mode-vi v send -X begin-selection

if-shell 'uname | grep -q Darwin' {
    bind C-c run 'tmux save-buffer - | reattach-to-user-namespace pbcopy'; \
    bind C-v run 'tmux set-buffer $(reattach-to-user-namespace pbpaste); tmux paste-buffer'
    bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'tmux save-buffer - | reattach-to-user-namespace pbcopy'; \
    bind -T copy-mode-vi C-v send -X rectangle-toggle \; send -X begin-selection; \

    # Selection with mouse should copy to clipboard right away, in addition to the default action.
    unbind -n -T copy-mode-vi MouseDragEnd1Pane; \
    bind -T copy-mode-vi MouseDragEnd1Pane send -X copy-selection-and-cancel\; run 'tmux save-buffer - | reattach-to-user-namespace pbcopy > /dev/null'; \

    # Middle click to paste from the clipboard
    unbind MouseDown2Pane; \
    bind -n MouseDown2Pane run 'tmux set-buffer $(reattach-to-user-namespace pbpaste); tmux paste-buffer'
}

if-shell '[[ $(uname -s) = Linux ]]' {
    bind C-c run "tmux save-buffer - | xclip -selection clipboard -in"; \
    bind C-v run 'tmux set-buffer $(xclip -selection clipboard -out); tmux paste-buffer'; \
    bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'xclip -selection clipboard -in'; \
    bind -T copy-mode-vi C-v send -X rectangle-toggle \; send -X begin-selection; \

\   # Selection with mouse should copy to clipboard right away, in addition to the default action.
    unbind -n -T copy-mode-vi MouseDragEnd1Pane; \
    bind -T copy-mode-vi MouseDragEnd1Pane send -X copy-selection-and-cancel\; run 'tmux save-buffer - | xclip -selection clipboard -in > /dev/null'; \

    # Middle click to paste from the clipboard
    unbind MouseDown2Pane; \
    bind -n MouseDown2Pane run 'tmux set-buffer $(xclip -o -sel clipboard); tmux paste-buffer'
}

@ghost
Copy link
Author

ghost commented Dec 13, 2020

Now that I think of it, maybe by just aliasing xclip to pbcopy on linux in the zshrc it would work with the same lines as in maxos:

alias pbcopy='xclip -selection clipboard -in'
alias pbpaste='xclip -selection clipboard -out'

@nicknisi
Copy link
Owner

I tested without reattach-to-user-namespace and it works well, so I removed that and pushed up. Fixed in dc09b2f. Thank you!

@nicknisi nicknisi closed this Dec 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant