-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add shorthand opts, plus many bug fixes and debugging features #88
base: master
Are you sure you want to change the base?
Conversation
-T is exactly equivalent to "-o -t TARGETS". -c is equivalent to "-selection clipboard" As a bonus, -b is a synonym for -c to be more friendly to people who are used to using `xsel`.
As requested by Åstrand for merge.
Working for all basic cases. Tab completion of filenames, all flags, all selections (case insensitive), and most TARGETS. ("Most" because this code cannot yet handle spaces in the property names.)
commit b16257c31702d9762c917790354561412507ff8d Merge: 44e9f8b 001c253 Author: b9 <[email protected]> Date: Wed Oct 7 21:33:20 2020 -0700 Merge branch 'documentation' of https://github.com/hackerb9/xclip into documentation
Wrt reviewing the code: Good that you are using "fixup" messages, but it would be even better if you could do git rebase -i --autosquash. Then force push. Can you do that? |
Yes, I can do that. I just need to learn a little more. I actually attempted to rebase -i (a few different ways) before the pull request, but failed. Git gave me some guff, saying there was a "conflict" during the interactive rebase. I'll keep trying and figure it out. |
88250e4
to
9b2fb3c
Compare
Add reqstr[], table of requests indexed by op-code.
Tidying up, decrease noise in -h Change sleep to 0.01 between ./xclip -i and ./xclip -o
get rid of needless variable
Squashed commit of the following: commit 126d057 Author: b9 <[email protected]> Date: Fri Oct 23 03:52:50 2020 -0700 Add mode 12: call xcin with too large a chunk, cause alloc error commit 1c8c9dc Author: b9 <[email protected]> Date: Fri Oct 23 03:50:26 2020 -0700 Move requestor struct to shared .h file, add xcatomstr() commit eb63b05 Author: b9 <[email protected]> Date: Fri Oct 23 03:48:07 2020 -0700 When refusing INCR request on alloc error, delete property Don't just send the Notification with the None property. commit 32dedff Author: b9 <[email protected]> Date: Fri Oct 23 03:11:37 2020 -0700 xcatomstr(): return a string describing an atom, ignoring errors commit 4fc9b95 Author: b9 <[email protected]> Date: Thu Oct 22 04:05:14 2020 -0700 Use property to also id requestor uniquely commit cf0a192 Author: b9 <[email protected]> Date: Wed Oct 21 17:37:28 2020 -0700 Max request size should be 16x larger We were dividing by 4 when we should have been multiplying by 4. We also forgot to subtract bytes for the request header. X11R5 spec said each request header was 4 bytes. Experimentally, I'm finding that it is 32-bytes. 20 October 2020. /usr/include/X11/SelectionI.h:MAX_SELECTION_INCR leaves room for 100 bytes. #define MAX_SELECTION_INCR(dpy) ( \ ((65536 < XMaxRequestSize(dpy)) ? \ (65536 << 2) : \ (XMaxRequestSize(dpy) << 2))-100) commit 8aa4619 Author: b9 <[email protected]> Date: Mon Oct 19 22:44:54 2020 -0700 !Fixup commit a897a9d Author: b9 <[email protected]> Date: Mon Oct 19 22:41:13 2020 -0700 add xcchangeprop() wrapper to handle errors from xchandler(). commit 40bedfe Author: b9 <[email protected]> Date: Mon Oct 19 22:19:24 2020 -0700 Checkpoint commit 8cb43c0 Author: b9 <[email protected]> Date: Sun Oct 18 07:18:19 2020 -0700 Move old unicode lower commit 0f53f22 Author: b9 <[email protected]> Date: Sat Oct 17 20:16:10 2020 -0700 Add fixme for ICCCM XExtendedMaxRequestSize
… shorthandopts Toss out minor changes on this branch
@astrand: Have you had a chance to try out this branch? I've been using it as my everyday xclip and have had no problems. I think I've squashed the history as much as makes sense logically (and that I can do without causing strange git breakage). Did I do enough? If it's helpful to you, I am willing to try learning more about how to reorder commits for squashing. Alternately, I've found it useful to look at the overall diff instead of the patch history: https://github.com/astrand/xclip/pull/88.diff |
I have now done a checkout, build and quick test run. Basic test seems to work, but strange behaviour when running without arguments:
The output string seems to vary. |
Also, changed 'rm -rf' to less dangerous 'rm' and 'rmdir'.
Hi @astrand, That's actually what it is supposed to do: “Sensible stdin”: If stdin is a keyboard (tty), xclip will default to -output. The old behavior was to silently block, waiting for the user to type Control-D at the beginning of a line. As we saw in a bug report last week, the old behavior can lead to user confusion where they think xclip is broken. But confusion isn't the primary reason for the change. I believe it's a major improvement in usability as users no long need to think about whether -i or -o is required. (E.g., this now works: This is actually the issue that got me motivated to start working on the If you want, I can share more thoughts about why it's a good and important change. As for stability, I have personally tested my changes quite extensively, even adding new tests to xctests and creating a new tool ( |
Hi again, thanks for explaining this. Haven't noticed this in the other pull requests. Wrt the "sensible stdin", I'm not convinced. I see several problems with it:
There's some discussion about this principle here: https://news.ycombinator.com/item?id=8484718 For me, changing the behaviour slightly by checking if stdin is a tty might be OK, but in this case the main operating mode is changed. I think this can lead to a lot of confusion; the SSH example above is just one such case. I am sure there are many others. Perhaps it is possible to find some "smaller" solution or middle ground? For example, require -o for output as it is today, but require explicit -i if stdin is a tty? Ie exit with an error/hint if tty without -i. |
I've thought hard about this and I've written up responses only to find that they are too verbose. I don't want to waste your time, but I do want to communicate. Let's see if I can manage it this time. ☺ The "middle ground" solution of requiring users to specify either -i or -o to choose a mode is actually further away from my goal of requiring less cognitive effort from users. If an argument is always required to pick a mode, it'd be better to just have two utilities — I could, however, go for a similar situation, where the documentation would say: “Xclip has two modes: in and out. One or the other is required to be specified in careful usage, but the casual user may leave them off and let xclip "guess" which is meant (based on stdin being a tty). Xclip nearly always gets it right, but don't rely on that behaviour: always explicitly specify either |
Thanks :-)
Don't agree on this one, though. For example, "tar" can both extract and and create archives.
I think we take a step back and consider which problem we actually are trying to solve; why the current implementation is problematic. For example, the problem with users getting confused by "xclip" without arguments (waiting for input from TTY) can be solved with a warning. When in doubt, I think it is best to look at how existing Linux utils works, and I haven't seen many commands which automatically detects the mode based on "position in the pipeline" so to say. |
I believe these are the problems we are trying to solve:
The user getting confused by
According to the Principle of Least Surprise, this is also how Regarding the points you made in #88 (comment):
I do not believe there are many scripts that depend on this particular behavior. And even if there are, fixing them would be very easy, on top of making them more robust in general. Furthermore, we will not be able make the behavior of
These are some of the tools that detect their “position in the pipeline” to provide a better user experience. The standard even explicitly exempts some of them:
By saying “use it as part of another pipeline”, are you talking about
There are many other ways of doing this, like heredocs ( In conclusion: |
Thanks a lot for this extensive feedback! A few comments below:
For me, such a behaviour is actually surprising. As you can see in my comment on 8 Nov 2020, I was actually thinking it was a bug. Wrt git, for example, I actually type "git branch | cat" several times per day, to work around that "helpful" feature of starting a pager. Ok, I admit that probably the "git branch | cat" is used more seldomly than "git log | less". So it saves some keystrokes per day, but still not very obvious or inituitive.
I cannot really see how they would be more robust than with the existing behaviour, where the mode needs to be specified?
I agree on this one!
You need to make sure X11 forwarding is setup (ie use -X etc).
Personally, I'm not convinced. However, it seems there are at least 3 persons positive for this change now, and I'm not that active in the project any longer. Therefore, I think it would be wrong for me to "block" this change. Therefore, it's OK with me to merge this feature. Thanks again for your dedicated work :-) |
Hi, I am experiencing the issue in #43 using master despite it apparently being fixed. Using the hackerb9 branch fixes this issue for me. Is there any plans to push this forward? I am, unfortunately, not versed in this code, C, or git well enough to help out a whole lot. If you know of a way I can use git to simply test which set of commits makes this work, I can try that; and if I can find a working combo, a separate pull request could be made where only those changes that fix my variation of #43 are merged. That way the blocking issues with the flags aren't in the way. I have been trying to do this on my own with cherry-pick and testing individual commits with no success. I'll continue as I have time. |
1). File handles from fopen should be closed by fclose after use. Free fil_handle in the function doIn after reading date from each file. 2). Memory allocated from xcmalloc/xcrealloc should be freed after use. Free file_names in the function doIn after reading data from all files.
* fix shellcheck warnings * fix mix of tabs & spaces * make compatible with more shells Doesn't change any functionality, while making the code more robust.
Add bold to "PASS" and standout to "FAIL", if the terminal can handle it. Various placement and alignment. Made sure FAIL messages also looked right. Singular for "1-lines of text". Et cetera, et cetera.
Previously, I was using the -e option (exit immediately wth an erorr if any command fails) and using killall xclip during cleanup and not checking the results.
I have the same issue as @brodyck. Would it be possible to at least merge just the part that fixes #43? |
@astrand: please double-check that this works as expected and introduces no new problems. I have been testing this out (on the branch "shorthandopts") for a while and am confident in it. It seems quite reliable and doesn't fail in certain cases (see borked.c) that cause the current release of xclip to fall over.
Some features: