In the manpage of xclip
-selection
specify which X selection to use, options are
"primary" to use XA_PRIMARY (default),
"secondary" for XA_SECONDARY or
"clipboard" for XA_CLIPBOARD
Note that only the first character of the selection specified with the -selection option is important.
This means that "p", "sec" and "clip" would
have the same effect as using "primary", "secondary" or "clipboard" respectively.
The following for using clipboard selection works
xclip -sel clip < ~/.ssh/id_rsa.pub
the manpage says that clipboard
can be shortened to clip
, but doesn't say that -selection
can be shortened to -sel
.
So why does it work? Does this feature for specifying an option belong to xclip
, or also to many other applications besides xclip
?
Best Answer
xclip
uses the X Toolkit library, which does the options-parsing. All of the options can be abbreviated. The library only gives an error if there is an ambiguity.Options, of course, are things like
-select
which can be abbreviated as-sel
(possibly even-s
).xterm
uses the same library, same behavior. It uses special cases (outside the library) to make the-v
command a unique abbreviation for-version
, etc.X Toolkit uses a single dash
-
for options, and does not distinguish between "short" and "long" because it is not an extension ofgetopt
. As I pointed out in Single dashes-
for single-character options, but double dashes--
for words?, it was introduced around the same time as GNU getopt, which did extendgetopt
. This was before POSIX came along, butAT&T
getopt
had several years of use, establishing its role for single-character options. GNUgetopt
uses a double-dash--
to denote long options.Noting a long digression, you can read the source code for GNU getopt (which is unrelated to
xclip
) from its git repository, e.g.,