Comment by em-bee

2 days ago

and new shells are developing features to handle structured data like json:

here is an elvish shell command that converts a freetube playlist from json into a list of urls grouped by author:

    for i (cat 'freetube-playlist-favorites.db' | from-json)["videos"] { 
      mkdir -p $i['author']
      print http://youtu.be/$i['videoId'] >> $i['author']/get }

here is one to get a list of devices connected to my zerotier network

    curl -s -H "Authorization: token <redacted>" "https://api.zerotier.com/api/v1/network/<redacted>/member" | 
      all (from-json) | 
      order &key={|d| put $d[name]} | 
      each { |device| 
             var t = (printf "%.0f" (/ $device[lastSeen] 1000))
             if (> 20000000 (- (date '+%s') $t))  { 
               print (date -R --date='@'$t) $device[config][ipAssignments] $device[name] "\n" } }

those are not scripts saved in a file. i run these directly on the commandline. ignore the elvish syntax, focus on the ease of accessing values from the json data. those are just two examples, though i recently discovered an ls replacement that optionally outputs json, that will be interesting to use.

Great example! How do you like using elvish? Even though I am a proponent of structured data and like PowerShell a lot (mentioned in a nearby comment of mine), I use fish as my regular shell. Big fan of fish's careful focus on user experience, but would be open to trying something structured.

  • I'ma huge fan of `fish` myself, but I've been watching `elvish` for a while now, and some of their scripting stuff really is awfully nice.