diff --git a/clipboard-adapter.sh b/clipboard-adapter.sh index af86763..b110c2c 100755 --- a/clipboard-adapter.sh +++ b/clipboard-adapter.sh @@ -53,7 +53,9 @@ main() { exit 0 ;; copy) - perform_copy + input="$(cat -)" + printf "%s" "$input" | perform_copy + printf "%s" "$input" | perform_primary ;; insert) # Also copy when doing insert to give users a fallback in case automatic @@ -112,6 +114,30 @@ perform_copy() { esac } +perform_primary() { + tool=$(find_copy_tool) + + case "$tool" in + xsel) + xsel --primary --input + ;; + xclip) + xclip -selection primary -in + ;; + wl-copy) + wl-copy --primary + ;; + "") + show_error "Could not find any tool to handle copying. Please install a clipboard handler." + exit 1 + ;; + *) + show_error "$tool has no implementation for copying yet" + exit 2 + ;; + esac +} + perform_insert() { tool=$(find_insert_tool)