-
-
Notifications
You must be signed in to change notification settings - Fork 584
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
Rewrite picom-trans #634
Rewrite picom-trans #634
Conversation
Codecov Report
@@ Coverage Diff @@
## next #634 +/- ##
=======================================
Coverage 39.90% 39.90%
=======================================
Files 46 46
Lines 9484 9484
=======================================
Hits 3785 3785
Misses 5699 5699 |
This comment has been minimized.
This comment has been minimized.
Thanks for your work! I am not very experienced in bash however, @tryone144 what about you? It feels bad to ask this after you have done all this work, but how do you feel about rewriting this script in a different language, say Python? I think things like argument parsing is going to be much simpler. |
Actually, I had previously thought of writing it in a different language. I know python, C, and sh. Writing it in Python would mean adding yet another dependency. The lesser dependencies, the better, IMO. Writing it in C would not add dependency, but then, it would make a compiled binary, which will be harder to debug than an interpreted language. Ultimately, I decided to write in POSIX sh. |
EDIT: After some googling, I have found out that yes, that use-case is actually required by GNU. (not POSIX. POSIX doesn't support long options like Lines 98 to 100 in be24c0d
@yshui The purpose of the above lines is to allow arguments to be specified like this -
Which shall be the equivalent of -
My question was, running |
All arguments shall be parsed by getopts. Long arguments shall be transformed into POSIX-compatible ones before invoking getopts.
Python is pretty ubiquitous, it's not something I would worry about. |
First convert all long options to POSIX-compatible ones, then parse them using getopts.
Actually, I did not re-write the whole script. I just re-structured it, re-wrote the argument-parsing from scratch, and make the whole script as POSIX-compatible as I could. That's why I stuck with Re-writing it in python would need 10 times more effort than what I did here. Also, I don't think python is really suited of this kind of text-processing task. I don't know any Also, IMO bash is even more ubiquitous than python. |
@yshui Please tell me if you can find any bugs. I have fixed all bugs I could find. |
Thanks, I am still reviewing it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The restructured code is definitively more readable than the old.
This has however introduced some (breaking) changes and/or bugs. Particularly, the parsing of +-OPACITY%
is still not quite working correctly.
- Gracefully error out when invalid longopts are given - Fix a typo (winidtype=-window -> winidtype=-id) - Allow trailing %-signs in opacity - Update the validification regex - Strip trailing % signs before any calculation
reset_opacity doesn't need a window to be specified
Show relevant error message if no opacity is specfied.
The allowed opacity is 0-100, not 1-100.
If $target_opacity is specified and $current_opacity is unset, then --toggle causes the opacity to be set to $target_opacity instead of 100% See this link for the discussion regarding the behaviour of --toggle #634 (comment)
"$0" inside functions contains the function name, not the name of the actual executable.
printf instead of echo would be nice. Tl;DR: At a very high level, printf is like echo but more formatting can be done. Reasons
PerformanceConcerning performance, I always had in mind that echo was faster than printf because the later has to read the string and format it. But testing them with time (also built-in) the results say otherwise: $ time for i in {1..999999}; do echo "$i" >/dev/null; done
real 0m10.191s
user 0m4.940s
sys 0m1.710s $ time for i in {1..999999}; do printf "$i" >/dev/null; done
real 0m9.073s
user 0m4.690s
sys 0m1.310s Telling printf to add newline characters, just as echo does by default: $ time for i in {1..999999}; do printf "$i\n" >/dev/null; done
real 0m8.940s
user 0m4.230s
sys 0m1.460s That is obviously slower than without printing the |
@yshui didn't like how hacky getopts was made in commit 0f4283a - #634 (comment) I agree. It does look hacky. Let's tackle the problem using a different approach that doesn't look so hacky :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @subnut.
If I am not mistaken we should have reached a state that is working with all functionality from before. Parsing of the arguments should be more robust now and if anything the script appears to be a tad faster or at least not slower than before. 👍
I haven't been able to test every (im-)possible argument combination in the old implementation, but the examples at the top still give the same results.
Please take a look at the last bug I could find. Other than that, I think it is best to squash at least the bugfix / fixup commits into the commit they fix.
Don't get_current_opacity() if not needed (ie. if target_opacity is not relative)
Good idea! I will squash the bugfix commits, and also change the commit message style from |
So, use printf '%s' "-n"
I have reduced the number of commits from 30 to 20. Do let me know if it needs to be decreased further. I have merged all the bugfix commits with the commits which introduced the bug. Also, I have merged some other-than-bugfix commits, like, say a commit introduces a block of code that is later removed again a few commits later. |
I am inclined to just squash the whole PR |
But that would remove the (valuable, IMHO) commit messages, right? |
Current picom-trans prints the whole path to the file when it prints error messages or help output -
But in this PR, I've changed it to show only the basename of the file path. i.e. it will only show the last part of the whole path
Is this change accepted? Or should I revert it to the old behavior of printing the whole path? |
If there are design decisions, explanation of how code works, etc. in the commit messages, then they can also be recorded as code comments. And IMO they are more visible there. Bug fixes (unless they are recurring pitfalls, in that case they could be code comments too), indentation fixes, etc. should be squashed away. Am I missing some other types of valuable commit messages that you had in mind? |
OK. Agreed. And it seems that in the midst of squashing all the commits, some important bugfixes got missed out. So I'm going to have to revert from the reflog anyway. Sigh. Let me go find the last valid commit from the @yshui What's your opinion on this change? |
I think this PR is now ready to Squash and Merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for your work on this @subnut 👍
I just now remembered, I forgot about the LICENSE! I would like to LICENSE my code under MIT, but then again, I don't know under what license Christopher Jeffrey released the initial version upon which my work is based, and whether that license is compatible with MIT. Hey @chjj, is it you who wrote the original EDIT: According to this, it seems Christopher licensed his original version with the MIT/Expat License, which is the exact same license that I was intending to license my code under. @yshui Since you are the maintainer, give me advice on where to mention about the License. Should I place it as a comment block on the top of the file? Or is there some other file? |
@subnut put a |
Rewrite picom-trans (yshui#634) Notable changes: * Support arguments like `--arg=val` * Allow trailing %-signs in opacity * Improve error message * Improve compatibility across different shells
Rewrite picom-trans (yshui#634) Notable changes: * Support arguments like `--arg=val` * Allow trailing %-signs in opacity * Improve error message * Improve compatibility across different shells
Rewrite picom-trans (yshui#634) Notable changes: * Support arguments like `--arg=val` * Allow trailing %-signs in opacity * Improve error message * Improve compatibility across different shells
I have re-written picom-trans to be better understandable. Also added comments.