astrand / xclip

Command line interface to the X11 clipboard
GNU General Public License v2.0
1.04k stars 75 forks source link

Sensible stdin handling #65

Closed hackerb9 closed 3 years ago

hackerb9 commented 4 years ago

This patch should not affect any current users as they can continue to use -i and -o as they always have. However, for those who are slightly lazier (or forgetful, as in my case), xclip will now use a sensible mode if you forget to specify input or output.

Specifically: Default is still "input" mode, but if stdin is a user's keyboard, xclip will switch to "output" mode. (Unless the user invokes xclip with the -i flag, of course). That means xclip will do the right thing at the command line without having to specify any extra options:

$ echo hello | xclip
$ xclip
hello
$ xclip README
$ xclip | wc
    131     556    3921

Note that "input" mode is always used for filenames, same as before. The default mode is "output" only when a tty would be read as stdin.

Of course, if one is writing a shell script, it is probably best to still use the -i and -o flags for clarity and just in case there's some odd corner case where the presumed default is incorrect.