xaizek / dit (License: GPLv3) (since 2018-12-07)
Command-line task keeper that remembers all old values and is meant to combine several orthogonal features to be rather flexible in managing items.
Commit 88c7337b61c996822d048a8d82ddb6c21343fd33

Provide sample scripts for "export" command
Need to mention them somewhere (like in a README or maybe even install
on `make install`).
Author: xaizek
Author date (UTC): 2016-06-14 16:59
Committer name: xaizek
Committer date (UTC): 2016-06-14 16:59
Parent(s): 22204b2927108deb4573cf3d197b82e7c05fb017
Signing key: 99DC5E4DB05F6BE2
Tree: b1ec1556ac60bdfe51bf7281e9160a2a0bf8a5c2
File Lines added Lines deleted
scripts/export-template-pipe.bash 40 0
scripts/export-template.bash 30 0
File scripts/export-template-pipe.bash added (mode: 100755) (index 0000000..0ea91d8)
1 #!/bin/bash
2
3 # This script receives all data item-by-item (all fields of one item followed by
4 # all fields of another and so on).
5 # Commented code shows how received data can be collected and accessed.
6 #
7 # Usage example:
8 # dit export - | ./export-template-pipe.bash
9
10 # This function can use $data array to process item fields as key-value pairs.
11 function process_item()
12 {
13 for key in "${!data[@]}"; do
14 :
15 # echo "Key: $key"
16 # echo "Value: ${data[$key]}"
17 done
18
19 # Display title or report its absence.
20 echo "${data[title]:-<no title>}"
21 }
22
23 # Compose an associative array from key-value pairs.
24 declare -A data
25 while read -rd $'\0' line; do
26 if [ -z "$line" ]; then
27 process_item
28 unset data
29 declare -A data
30 continue
31 fi
32
33 # echo "Line: $line"
34 key="${line%%=*}"
35 value="${line#*=}"
36 # echo "Key: $key"
37 # echo "Value: $value"
38
39 data[$key]="$value"
40 done
File scripts/export-template.bash added (mode: 100755) (index 0000000..a2795ee)
1 #!/bin/bash
2
3 # This script is invoked once for each item.
4 # Commented code shows how received data can be collected and accessed.
5 #
6 # Usage example:
7 # dit export ./export-template.bash
8
9 declare -A data
10
11 # Compose an associative array from key-value pairs.
12 for arg; do
13 # echo "Arg: $arg"
14 key="${arg%%=*}"
15 value="${arg#*=}"
16 # echo "Key: $key"
17 # echo "Value: $value"
18
19 data[$key]="$value"
20 done
21
22 # Visit each array entry.
23 for key in "${!data[@]}"; do
24 :
25 # echo "Key: $key"
26 # echo "Value: ${data[$key]}"
27 done
28
29 # Display title or report its absence.
30 echo "${data[title]:-<no title>}"
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/dit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/dit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master