3

I use xclip to copy the contents of the clipboard and pipe them to another application. However, if the last line that was copied doesn't have an end of line character, it doesn't show in the application.

Question: Is there a way to add an end of line/newline at the end of clipboard contents before piping the value across?

The following gif shows the behavior of (1) first copying without going to the end of the line and (2) second copying with going to the end of the line, and how the result is different in the terminal. Notice the relationship between what was copied and the prompt.

enter image description here

The application that I'm using which makes use of xclip would not read anything in with the first option, and would read the line correctly with the second option.


A little bit more information here...

1

The command:

printf "$(xclip -o clipboard)\n"| xclip -selection c

extends the content of the clipboard into a new string, adding a newline.

Subsequently, the edited string is copied into the clipboard (again) by:

xclip -selection c
  • This seems to do what I'm looking for. For the actual application, I stop before the pipe and just use the output resulting from the printf step. Thanks! – Ananda Mahto Jun 1 '15 at 2:02
  • Since you started with a Mac, don't suppose you know if this would work with pbpaste too... – Ananda Mahto Jun 1 '15 at 2:06
  • @AnandaMahto I am afraid in my Mac days, all I was capable of is push some buttons :) – Jacob Vlijm Jun 1 '15 at 6:28
  • No problem. Will see what I can come up with :-) – Ananda Mahto Jun 1 '15 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.