xsel

Program for manipulating the X clipboard
git clone https://git.sinitax.com/kfish/xsel
Log | Files | Refs | README | LICENSE | sfeed.txt

commit 583f1a441c93686b99e82d8be621f5f06b669e31
parent c08f1aa232b8e195cba2a817fbd59cc976834619
Author: conrad <conrad@9c49b5d1-7df3-0310-bce2-b7278e68f44c>
Date:   Wed, 30 Apr 2008 02:40:51 +0000

When stdout is a tty, use stderr to ensure there is a newline before
the shell prompt.

(Modified) patch from Yair K.:

If the used selection does not end with a newline, then:
 A) If 'xsel -o' than the command prompt may overwrite the last line (depends
on $PS1, shell, etc. but I think quite likely to happen)
 B) 'xsel -a -o -i' doesn't display the last line (on Linux at least). The
last line will still exist after appending, but it isn't displayed. This is
(I suspect) because stdout is line-buffered, so stdout isn't flushed yet.


git-svn-id: http://svn.kfish.org/xsel/trunk@249 9c49b5d1-7df3-0310-bce2-b7278e68f44c

Diffstat:
Mxsel.c | 12+++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/xsel.c b/xsel.c @@ -2158,7 +2158,16 @@ main(int argc, char *argv[]) if (do_output || !dont_output) { /* Get the current selection */ old_sel = get_selection_text (selection); - if (old_sel) printf ("%s", old_sel); + if (old_sel) + { + printf ("%s", old_sel); + if (!do_append && *old_sel != '\0' && isatty(1) && + old_sel[xs_strlen (old_sel) - 1] != '\n') + { + fflush (stdout); + fprintf (stderr, "\n\\ No newline at end of selection\n"); + } + } } /* handle input and clear modes */ @@ -2168,6 +2177,7 @@ main(int argc, char *argv[]) clear_selection (selection); } else if (do_input || !dont_input) { + if ((do_output || !dont_output) && isatty(1)) fflush (stdout); if (do_append) { if (!old_sel) old_sel = get_selection_text (selection); new_sel = copy_sel (old_sel);