File: dit-import

package info (click to toggle)
vifm 0.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,252 kB
  • sloc: ansic: 179,567; sh: 5,445; makefile: 723; perl: 347; python: 76; xml: 26
file content (119 lines) | stat: -rwxr-xr-x 2,712 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash

# This script updates reduced in-tree dumps of TODO and BUGS files by importing
# their contents from dit and applying necessary formatting.
#
# Invocation:
#  * without arguments updates both files;
#  * with "bugs", "todo" or "all" argument updates one or both files.

function print_wrapped()
{
    local OLDIFS="$IFS"
    IFS=$'\n'
    local lines=( $(echo "$@" | par -w78 -p2) )
    IFS="$OLDIFS"

    local first=1
    for line in "${lines[@]}"; do
        if [ "$line" = sep ]; then
            first=1
            continue
        fi
        if [ $first = 0 ]; then
            echo -n '  '
        fi
        echo "$line"
        first=0
    done
}

function process_item()
{
    prefix="$1"

    if [ "${data[status]}" = partial ]; then
        local mark=" (partially done)"
    fi

    lines="$lines$prefix${data[title]}$mark"$'\n\nsep\n\n'
}

function process_items()
{
    prefix="$1"

    lines=""
    declare -A data
    while read -rd $'\0' line; do
        if [ -z "$line" ]; then
            process_item "$prefix"
            unset data
            declare -A data
            continue
        fi

        key="${line%%=*}"
        value="${line#*=}"

        data[$key]="$value"
    done
    print_wrapped "$lines"
}

function list_realm()
{
    local title="$1"
    shift

    local out="$(dit .vifm export - status!=done status!=dismissed "$@" |
                 process_items '  * ')"
    if [ -n "$out" ]; then
        echo
        echo "$title:"
        echo "$out"
    fi
}

function make_bugs()
{
    for type in bug issue glitch regression fix; do
        dit .vifm export - 'status!=done' 'status!=dismissed' "type==$type" |
        process_items '* '
    done
}

function make_todo()
{
    list_realm 'Basic things' realm==basic
    list_realm 'Documentation' realm==docs
    list_realm 'Vi(m) specific features' realm==vimlike
    list_realm 'Windows' realm==win
    list_realm 'Possible things to add' realm==possible
    list_realm 'Questionable things' realm==questionable
    list_realm 'Code improvements' realm==code
    list_realm 'Other' realm!=basic realm!=docs realm!=win realm!=vimlike \
                       realm!=possible realm!=questionable realm!=code \
                       type!=bug type!=issue type!=glitch type!=regression \
                       type!=fix
}

function usage()
{
    echo "Usage: $(basename $0) [bugs|todo|all]"
    exit 1
}

if [ $# -gt 1 ]; then
    usage
fi

dir="$(readlink -f "$(dirname "$0")")"

case "$1" in
    bugs)   make_bugs > "$dir/../BUGS" ;;
    todo)   make_todo | tail +2 > "$dir/../TODO" ;;
    all|"") make_bugs > "$dir/../BUGS"
            make_todo | tail +2 > "$dir/../TODO" ;;
    *)      usage ;;
esac