TickTick is “just a fun hack.” But it does look intriguing, it has some APIs for manipulations and accessing, and it doesn’t just parse JSON, but also manipulate using the APIs that it provides.
The example.sh tells a lot what it can do.
First, you load the library:
#!/bin/bash
. ticktick.sh
Then, you embed the JSON, note that you can parameter expand:
bob=Bob `` people = { "HR" : [ "Alice", $bob, "Carol" ], "Sales": { "Gale": { "profits" : 1000 }, "Harry": { "profits" : 500 } } } ``
One more thing I noticed is the syntax highlighting works quite well even for the `` block in Vim.
You can insert new objects, in this case, an Engineering department of three employees:
echo Base Assignment `` people.Engineering = [ "Darren D", "Edith E", "Frank F" ] `` printEmployees
The printEmployees function utilizes a loop on the expanded results of the TickTick:
function printEmployees() { echo echo " The ``people.Engineering.length()`` Employees listed are:" for employee in ``people.Engineering.items()``; do printf " - %s\n" "${!employee}" done echo }
This part produces the following result:
Base Assignment The 3 Employees listed are: - Darren D - Edith E - Frank F
More operations such as push and pop, shift, and index:
newPerson="Isaac I" echo Pushed a new element by variable, $newPerson onto the array `` people.Engineering.push($newPerson) `` printEmployees echo Shifted the first element off: `` people.Engineering.shift() `` printEmployees echo Popped the last value off: `` people.Engineering.pop() `` printEmployees echo Indexing an array, doing variable assignments person0=``people.HR[0]`` echo $person0 ``people.HR[1]``
The results are:
Pushed a new element by variable, Isaac I onto the array The 4 Employees listed are: - Darren D - Edith E - Frank F - Isaac I Shifted the first element off: Darren D The 3 Employees listed are: - Edith E - Frank F - Isaac I Popped the last value off: Isaac I The 2 Employees listed are: - Edith E - Frank F Indexing an array, doing variable assignments Alice Bob
TickTick was born on 2011-12-02, just three years ago, it is based on JSON.sh, therefore under the MIT License and Apache License Version 2.0, written by Chris McKenzie, currently git-05453ed (2014-11-28, post v1.0 (2012-08-20)).
The code is little over 10 KB in file size and 277 lines, not a small one, but not huge, either. I don’t know if it runs fast enough, the performance can be only drawback, as it already said “You may want to consider using mature languages like Ruby or Perl to solve actual real life problems.”
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.