diff --git a/README.md b/README.md index 0226ba2..f501c35 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,31 @@ Configuration - Y (shift-y) — "put" selection. Equivalent to copying a selection, and pasting it to the command line. + +### Default and Preferred Clipboard Programs + +tmux-yank does its best to detect a reasonable choice for a clipboard +program on your OS. + +If tmux-yank can't detect a known clipboard program then it uses the +`@custom_copy_command` tmux option as your clipboard program if set. + +If you need to always override tmux-yank's choice for a clipboard program, +then you can set `@override_copy_command` to force tmux-yank to use whatever +you want. + +Note that both programs _must_ accept `STDIN` for the text to be copied. + +An example of setting `@override_copy_command`: + +``` tmux +# ~/.tmux.conf + +set -g @custom_copy_command 'my-clipboard-copy --some-arg' +# or +set -g @override_copy_command 'my-clipboard-copy --some-arg' +``` + ### Linux Clipboards Linux has several cut-and-paste clipboards: `primary`, `secondary`, and diff --git a/scripts/helpers.sh b/scripts/helpers.sh index 83fc06d..7e57358 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -27,6 +27,9 @@ custom_copy_command_default="" custom_copy_command_option="@custom_copy_command" +override_copy_command_default="" +override_copy_command_option="@override_copy_command" + # helper functions get_tmux_option() { local option="$1" @@ -75,6 +78,10 @@ custom_copy_command() { get_tmux_option "$custom_copy_command_option" "$custom_copy_command_default" } + +override_copy_command() { + get_tmux_option "$override_copy_command_option" "$override_copy_command_default" +} # Ensures a message is displayed for 5 seconds in tmux prompt. # Does not override the 'display-time' tmux option. display_message() { @@ -108,7 +115,9 @@ clipboard_copy_command() { # installing reattach-to-user-namespace is recommended on OS X - if command_exists "pbcopy"; then + if [ -n "$(override_copy_command)" ]; then + override_copy_command + elif command_exists "pbcopy"; then if command_exists "reattach-to-user-namespace"; then echo "reattach-to-user-namespace pbcopy" else