#5 "remove last newline" option

open
nobody
None
5
2014-11-25
2012-08-26
Philipp Spitzer
No

first of all: thank you very much for your work on xclip - a really great tool that I'm using
heavily.

The only thing that I was always missing is the possibility to optionally remove a newline
character if it is the very last one:

E.g. if I copied the date to the clipboard with
date | xclip
and wanted to tweak it at the following line of the bash, the following happened:

philipp@rigel:~$ date | xclip
philipp@rigel:~$ Sam Aug 25 18:11:14 CEST 2012
bash: Sam: Kommando nicht gefunden.
philipp@rigel:~$

Of cause that was because the date command generates a newline character at the very end, xclip
copied it correctly to the clipboard and after inserting it to the bash with Ctrl+Insrt the
newline character made the bash executing it immediately.

Recently I realized that there is a "workaround" for that: use "echo -n $(command) | xclip", e.g.:

philipp@rigel:~$ echo -n $(date) | xclip
philipp@rigel:~$ Sam Aug 25 18:14:47 CEST 2012

That works just fine. Now I could (and did) define a bash function that wraps xclip and does
the above. However, I don't think that other users will find this or a similar solution easily.

So I started to investigate, how much work it would be to add an option -r to xclip that
removes the very last newline character, if one is present. It was very easy to do and I ended
up with version "0.13" that works fine for me

I send you my modifications so that you can apply my changes to a future version of xclip if
you find them useful as well. (Even if you don't agree to add the -r option, I kindly ask you
to have a look at the patch because I did some other minor improvements (typos and "-s" as
shortcut for -selection) as well.

I started with the current trunk SVN revision 84 and did the following to create the patch:

philipp@rigel:~/projekte/xclip$ svn up
Revision 84.
philipp@rigel:~/projekte/xclip$ svn info
Pfad: .
URL: https://xclip.svn.sourceforge.net/svnroot/xclip/trunk
Basis des Projektarchivs: https://xclip.svn.sourceforge.net/svnroot/xclip
UUID des Projektarchivs: 02e78263-a932-0410-9e92-fa172c0799ba
Revision: 84
Knotentyp: Verzeichnis
Plan: normal
Letzter Autor: astrand
Letzte geänderte Rev: 84
Letztes Änderungsdatum: 2010-10-17 18:53:38 +0200 (Son, 17. Okt 2010)

philipp@rigel:~/projekte/xclip$ svn diff > suggestion.patch

Thank you,
Philipp

Discussion

  • "remove last newline" option

     
    Attachments