File this under #shell #functions I should have written years ago:
function grepc {
#Do a grep -c, but skipping files with no results
grep -c "$@" |grep -v ':0$'
}
File this under #shell #functions I should have written years ago:
function grepc {
#Do a grep -c, but skipping files with no results
grep -c "$@" |grep -v ':0$'
}
Oh, didn't know about -c. I usually just pipe to wc -l I guess.
-c, -l, -h, -H, and -q are my favorite #grep flags. :D
Huh, that almost became a [Marcel Duchamp] reference. š
I just use -v and -E
...and bash instead of zsh
...and grep/awk/sed instead of jq
...and firefox instead of chrome
...and the fediverse instead of facebook
Face it... I'm an unpopular-opinion neckbeard level boss. XD
cc: @mirabilos
@amin Absolutely.
@thedoctor @amin @sotolf @mirabilos
LISTEN, I've used grep/awk/sed for very nearly a quarter century, and I find the syntax of jq bewildering, so š
@rl_dane @thedoctor @sotolf @mirabilos
Most of those aren't for handling complex data types, though, just manipulating lines.
@amin @thedoctor @sotolf @mirabilos
So far, I've managed to bodge it together just well enough to do what I needed, but I really would like to get more familiar with jq.
@amin @rl_dane @thedoctor @sotolf jq is absolutely bewildering, especially the insistence on filtering (splitting the input stream is so hard and counter-intuitive), but itās an ok tool if you have JSON. Or YAML, which I [convert (user=pass public)] to JSON anywwy.
xmlstarlet is lovely!
@mirabilos @amin @thedoctor @sotolf
Is it possible to convert JSON to XML and then use xmlstarlet? š
@kabel42 @mirabilos @amin @thedoctor @sotolf
Sufficiently evil. XD
I remember when XML was the buzzword back in the late naughties.
@mirabilos @kabel42 @sotolf @thedoctor @amin
Well, if Google hates it, I'm probably on board by default. XD
@rl_dane @amin @thedoctor @sotolf yes, but youāll have to find out a schema you want to use.
Of course, you could just convertā¦
{ "foo": ["bar", "baz"], "bar": true }
⦠toā¦
<JSONObject>
<element name="foo"><JSONArray>
<element><JSONString>bar</JSONString></element>
<element><JSONString>baz</JSONString></element>
</JSONArray></element>
<element name="bar"><JSONBoolean>true</JSONBoolean></element>
</JSONObject>
⦠or worse (Apple āplistā), but I suspect youād rather have something semantically correct.
A lazy way to do this is with [iXML] (āinvisible XMLā, via @linguacelta of āAInātā fame); note youāll most likely want the draft spec, not the release, because the latter misses a way to specify an XML alias and just uses the grammar name, which must be unique, for the XML element name (so the above mapping, which has object elements and array elements, would not be possible with the 1.0 spec).
That being said, if you do want such a systematic mapping, I could write you a little jq script to do that.
Do note that U+0000 (ouch! I wish it werenāt), U+0001ā„U+0008, U+000Bā„U+000C, U+000Eā„U+001F, U+FFFEā„U+FFFF (ouch²!) are valid in JSON but not XML (and (X)HTML forbids further codepoints). xmlstarlet will likely refuse a document in which these occur (and no, even writing them as numeric entities like  is not permitted).
@rl_dane @mirabilos @thedoctor @sotolf
I do not feel up to subjecting my notifications to a revival of this thread right now. Bye y'all. :)
@rl_dane Those are so not comparable!

@kabel42 I see you also like to see the world burn.

@mirabilos @kabel42 @rl_dane @amin @thedoctor
Legacy is mostly the safe route to go anyway, tried and tested, I am the one that gets called if shit stops working, and I'd rather have something I know and makes sense, with tons of resources of administrators of the before times having struggled with them to help me figure out what is going on. Rather than modern stuff, with their ai documentation, discord "forums" and shipping their whole pc (docker) because they couldn't get their shit to work on a clean system :p
@kabel42 @mirabilos @rl_dane @amin @thedoctor
Hey I relied on that bug!
@sotolf @kabel42 @mirabilos @rl_dane @thedoctor
Oh haha so it was intentional. I was wondering.
@kabel42 @mirabilos @rl_dane @thedoctor @sotolf
Haha, you got it too! XD
@sotolf @kabel42 @mirabilos @rl_dane @thedoctor
Sometimes knowing the right xkcd is like shooting fish in a barrel. (Cruel, but easy.)
@amin @sotolf @kabel42 @mirabilos @thedoctor
That's why I use good old C-x M-c M-spacebarheat ;)
@kabel42 @amin @sotolf @mirabilos @thedoctor
A slant reference to xkcd 378 ;)
@mirabilos @thedoctor @kabel42 @sotolf @amin
ksh got started in... 1983? That's not legacy? XD

@mirabilos @kabel42 @sotolf @thedoctor @amin
Probably because people are addicted to the breakneck pace of "progress," novelty, and chasing their tails.
Maybe I'll spin up a laptop that only runs Unix v4 in a VM to try to spin the earth a tiny bit in the other direction. š
(Likely not)
@rl_dane @thedoctor @kabel42 @sotolf @amin @mirabilos
ksh is a type-safe, memory-safe language supporting modern paradigms like concurrency, higher-order functions and pattern matching. Its standard library even supports distributed applications and serverless architectures as well as microservices.
Not sure what should be legacy about that?
@mirabilos @nik @thedoctor @kabel42 @sotolf @amin
WAT. Sounds amazing, got an example?
Is this mksh or ksh93/2020?
@rl_dane @nik @thedoctor @kabel42 @sotolf @amin ksh2020 is completely gone. Thereās now āksh93u+mā by Martijn @mcdutchie as actively-developed version. ([Overview]⦠which I should update some day⦠oopsā¦)
This is, for now, an mksh thing; it stems from [a thread] by @navi in which she desires something like that for sh, but I chose to add it to the Korn shell-style function syntax instead because it is easy to add there without breaking anything and because it leaves the POSIX space open for future standardisation.
Itās deliberately not yet documented in the manpage or so because it can change at will and without prior notice and is, at this point, only something for people to play around with, to get a feeling for it, before it can become standardised.
(Also, I very much dislike the idea of adding it to the () of POSIX-style functions, as that would look too much like a subshell.)
general idea is:
| function (a b=foo) name { ⦠}
⦠is identical enough toā¦
| function name {
| a=$1; shift
| if (( $# )); then
| b=$1; shift
| else
| b=foo
| fi
| ā¦
| }
Note that default arguments can have side effects (like a parname=[] mutable default argument in Python)ā¦
function (count=$((++selfcount_cnt))) selfcount {
echo calling me for the ${count}th time
}
⦠but they are shortcut-evaluated (i.e. selfcount_cnt will not be incremented if selfcount is called with an argument), like in most logic (if (foo != NULL && foo->bar > 1) would crash if it werenāt).
The [commit message] has some more information, and of course you can read the diffs linked (user=pass public as usual⦠fscking LLM scrapersā¦) for more info, check.t contains some self-tests for this.
gl hf
@mirabilos @nik @thedoctor @kabel42 @sotolf @amin @mcdutchie @navi
That's lovely. š
@mirabilos @rl_dane @nik @thedoctor @kabel42 @sotolf @amin @mcdutchie
(Also, I very much dislike the idea of adding it to the () of POSIX-style functions, as that would look too much like a subshell.)
the main point of the thing was making the posix () not useless though ~w~
subshells arenāt allowed after a word like that in any context i can think of so imo someone would need to really go out of their way to make the syntax look confusing (most often subshells only pop up at the start of a command, or after a pipe, neither of which match function declarations much)
foo(nya mew=beep) {
echo $nya $mew
}
selfcount(count=$((++selfcount_cnt))) {
echo calling me for the ${count}th time
}
iām not a fan of the side effect thing much, but itās something i think we should have anyway due to specifying the default value the same as any normal assignment, something like mew=${2-beep}, so count=${1-$((++selfcount_cnt))}
@sotolf @thedoctor @kabel42 @mcdutchie @navi @amin @rl_dane @nik yes, thatās sort of how it works, except it actually inspects argc I think.
Hmmmm, use of $n (where n is number) in default args could be⦠"interesting". But, I think, possible.
@navi @sotolf @amin @rl_dane @kabel42 @mcdutchie @nik @thedoctor yes, it inspects argc, and it shifts after each, so $1 is always the one in question, though I donāt think you can do anythingn useful with it.
There also is no provision for namerefs yet (and thatās beyond POSIX and very shell-specific anyway). Might be interesting, perhaps with a prefix before the variable name.