shorter regex to get the timezone value#5
shorter regex to get the timezone value#5frederic-mahe wants to merge 2 commits intoMiSTer-devel:masterfrom
Conversation
first remove everything up to "timezone" included, then remove everything after the actual timezone value. In my opinion, this is easier to read, and it saves one subshell spawn by removing a pipe. Saves at least a millisecond :-)
|
Alternatively, using a more flexible pattern: TIMEZONE="$(curl -sLf "http://www.ip-api.com/json/" | sed -r 's/.*"timezone" *: *"([^"]*)".*/\1/')" |
|
Wouldn't this be more appropriate?
|
|
Thanks @vladc I didn't know it is possible to query json fields directly! @Locutus73 what do you think of that code simplification? |
|
That's brilliant... please excuse me, one of these days during the holydays I'll take some time and I'll review and merge all PR here and in the updater. Thank you. |
|
@frederic-mahe You should update this PR with @vladc suggestion. To do that locally, check out your patch-2 branch, then apply the change and push it. This PR should get updated automatically. If you want to get fancy you can (before or after you push the fix) do Then after you squash them you can |
whitespace cleaning, use herestring to avoid a pipe, protect variables with double-quotes and curly braces.
|
thanks for the advice @sigboe I chose to push a second commit, rather than squashing. This is advanced git, but squashing is clearer to me now, thanks to your explanation. |
first remove everything up to "timezone" included, then remove everything after the actual timezone value.
In my opinion, this is easier to read, and it avoids one subshell spawn by removing a pipe. Saves at least a millisecond :-)